-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Improve overall unit test coverage to above 90% 🧪
- Loading branch information
1 parent
de7c1ca
commit aeb32bb
Showing
162 changed files
with
5,500 additions
and
736 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const replaceBigInt = (_key: string, value: unknown) => | ||
typeof value === 'bigint' ? value.toString() : value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Channel } from './channel.entity'; | ||
|
||
describe('Channel Entity', () => { | ||
it('should create a Channel entity with the correct fields', () => { | ||
const channel = new Channel(); | ||
channel.id = 1; | ||
channel.sender = 101; | ||
channel.recipient = 202; | ||
channel.status = 'active'; | ||
channel.transfer_count = 5; | ||
channel.message_count = 15; | ||
channel.active_at = Date.now(); | ||
channel.proposed_max_capacity = 1000; | ||
channel.proposed_max_message_size = 256; | ||
|
||
expect(channel.id).toBe(1); | ||
expect(channel.sender).toBe(101); | ||
expect(channel.recipient).toBe(202); | ||
expect(channel.status).toBe('active'); | ||
expect(channel.transfer_count).toBe(5); | ||
expect(channel.message_count).toBe(15); | ||
expect(channel.active_at).toBeGreaterThan(0); | ||
expect(channel.proposed_max_capacity).toBe(1000); | ||
expect(channel.proposed_max_message_size).toBe(256); | ||
}); | ||
|
||
it('should handle nullable or optional fields correctly', () => { | ||
const channel = new Channel(); | ||
channel.id = 2; | ||
channel.sender = 103; | ||
channel.recipient = 204; | ||
channel.status = 'pending'; | ||
channel.transfer_count = 0; | ||
channel.message_count = 0; | ||
channel.active_at = 0; | ||
channel.proposed_max_capacity = 500; | ||
channel.proposed_max_message_size = 128; | ||
|
||
expect(channel.id).toBe(2); | ||
expect(channel.sender).toBe(103); | ||
expect(channel.recipient).toBe(204); | ||
expect(channel.status).toBe('pending'); | ||
expect(channel.transfer_count).toBe(0); | ||
expect(channel.message_count).toBe(0); | ||
expect(channel.active_at).toBe(0); | ||
expect(channel.proposed_max_capacity).toBe(500); | ||
expect(channel.proposed_max_message_size).toBe(128); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
import { ObjectType, Field, Int } from '@nestjs/graphql'; | ||
import { ObjectType, Field } from '@nestjs/graphql'; | ||
import { returnInt } from '../utils/graphql.utils'; | ||
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
@ObjectType() | ||
@Entity('channels') | ||
export class Channel { | ||
@Field(() => Int) | ||
@Field(returnInt) | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Field(() => Int) | ||
@Field(returnInt) | ||
@Column() | ||
sender: number; | ||
|
||
@Field(() => Int) | ||
@Field(returnInt) | ||
@Column() | ||
recipient: number; | ||
|
||
@Field() | ||
@Column() | ||
status: string; | ||
|
||
@Field(() => Int) | ||
@Field(returnInt) | ||
@Column() | ||
transfer_count: number; | ||
|
||
@Field(() => Int) | ||
@Field(returnInt) | ||
@Column() | ||
message_count: number; | ||
|
||
@Field(() => Int) | ||
@Field(returnInt) | ||
@Column('bigint') | ||
active_at: number; | ||
|
||
@Field(() => Int) | ||
@Field(returnInt) | ||
@Column() | ||
proposed_max_capacity: number; | ||
|
||
@Field(() => Int) | ||
@Field(returnInt) | ||
@Column() | ||
proposed_max_message_size: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app/app.module'; | ||
|
||
jest.mock('@nestjs/core', () => ({ | ||
NestFactory: { | ||
create: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('Application Bootstrap', () => { | ||
let mockApp: { listen: jest.Mock }; | ||
|
||
beforeAll(() => { | ||
mockApp = { | ||
listen: jest.fn(), | ||
}; | ||
|
||
(NestFactory.create as jest.Mock).mockResolvedValue(mockApp); | ||
}); | ||
|
||
it('should bootstrap the application and listen on the correct port', async () => { | ||
const { bootstrap } = await import('./main'); | ||
|
||
await bootstrap(); | ||
|
||
expect(() => NestFactory.create(AppModule, { cors: true })).not.toThrow(); | ||
|
||
expect(mockApp.listen).toHaveBeenCalledWith(4201); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app/app.module'; | ||
|
||
async function bootstrap() { | ||
export const bootstrap = async () => { | ||
const options = { cors: true }; | ||
const app = await NestFactory.create(AppModule, options); | ||
await app.listen(4201); | ||
} | ||
}; | ||
|
||
void bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ID } from '@nestjs/graphql'; | ||
import { Message, returnID, returnAssetArray, Asset } from './message.entity'; | ||
|
||
describe('Message Entity', () => { | ||
it('should create a Message entity with the correct fields', () => { | ||
const assets: Asset[] = [ | ||
{ | ||
enum_key: 'key', | ||
asset_module: 'module', | ||
amount: '1000', | ||
decimals: 6, | ||
symbol: 'TOKEN', | ||
}, | ||
]; | ||
|
||
const message = new Message(); | ||
message.message_hash = 'hash'; | ||
message.origin_event_index = 'event_1'; | ||
message.from_account_id = 'account_1'; | ||
message.origin_para_id = 1000; | ||
message.origin_block_timestamp = Date.now(); | ||
message.relayed_block_timestamp = Date.now(); | ||
message.block_num = 1; | ||
message.status = 'pending'; | ||
message.relayed_event_index = 'event_2'; | ||
message.dest_event_index = 'event_3'; | ||
message.dest_para_id = 2000; | ||
message.to_account_id = 'account_2'; | ||
message.confirm_block_timestamp = Date.now(); | ||
message.extrinsic_index = 'extrinsic_1'; | ||
message.relayed_extrinsic_index = 'extrinsic_2'; | ||
message.dest_extrinsic_index = 'extrinsic_3'; | ||
message.child_para_id = 3000; | ||
message.child_dest = 'child_dest'; | ||
message.protocol = 'protocol_1'; | ||
message.message_type = 'type_1'; | ||
message.unique_id = 'unique_1'; | ||
message.xcm_version = 2; | ||
message.assets = assets; | ||
|
||
expect(message.message_hash).toBe('hash'); | ||
expect(message.assets[0].symbol).toBe('TOKEN'); | ||
expect(message.xcm_version).toBe(2); | ||
expect(returnID()).toBe(ID); | ||
expect(returnAssetArray()).toStrictEqual([Asset]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { getRepositoryToken } from '@nestjs/typeorm'; | ||
import { MessageService } from './messages.service'; | ||
import { MessageResolver } from './messages.resolver'; | ||
import { Message } from './message.entity'; | ||
|
||
describe('MessageModule', () => { | ||
let module: TestingModule; | ||
let messageService: MessageService; | ||
let messageResolver: MessageResolver; | ||
|
||
beforeAll(async () => { | ||
const mockRepository = { | ||
find: jest.fn(), | ||
save: jest.fn(), | ||
}; | ||
|
||
module = await Test.createTestingModule({ | ||
providers: [ | ||
MessageService, | ||
MessageResolver, | ||
{ | ||
provide: getRepositoryToken(Message), | ||
useValue: mockRepository, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
messageService = module.get<MessageService>(MessageService); | ||
messageResolver = module.get<MessageResolver>(MessageResolver); | ||
}); | ||
|
||
it('should compile the module', () => { | ||
expect(module).toBeDefined(); | ||
}); | ||
|
||
it('should provide MessageService', () => { | ||
expect(messageService).toBeDefined(); | ||
}); | ||
|
||
it('should provide MessageResolver', () => { | ||
expect(messageResolver).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.