This repository was archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
integration tests for services #72
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6b49aff
test: added availability tests for all endpoints
rflechtner f42a492
test: e2e & integration tests for messaging endpoint
rflechtner b66b5aa
test: added e2e & integration tests for faucet
rflechtner 96b54af
feat: introduced in-memory db for testing
rflechtner 5695a04
ci: running integration tests in CI
rflechtner 4f0af5d
test: extended and improved faucet enpoint tests
rflechtner 135bb4d
test: added int. tests for ctype registry endpoint
rflechtner 0deed2d
chore: add CI tests timeouts
rflechtner 019ec63
fix: handle db init
rflechtner 3a348d3
test: integration tests for contacts endpoint
rflechtner 0e583f8
chore: added todos
rflechtner ed5dae1
Merge branch 'develop' into rf-integration-tests
rflechtner f8c1082
docs: documented in-memory db use
rflechtner ffa5328
refactor: use MockMongooseMod. everywhere for db mocks
rflechtner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
| BOOT_NODE_ADDRESS=ws://127.0.0.1:9944 | ||
| MONGODB_HOST=localhost | ||
| MONGODB_USER='' | ||
| MONGODB_PASS='' | ||
| SECRET=thisIsASecret |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ export class ContactsController { | |
| throw new BadRequestException('bad signature for hash') | ||
| } | ||
| } | ||
| this.contactService.add(contact) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. related to incorrect interfaces
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is 100% necessary.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'd be responding before the request has been fully processed if we don't await. Could silently fail and the requesting party would never know |
||
| await this.contactService.add(contact) | ||
| } | ||
|
|
||
| @Get() | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| import { MongooseModule } from '@nestjs/mongoose' | ||
| import { ConfigModule } from '../src/config/config.module' | ||
| import { MongoMemoryServer } from 'mongodb-memory-server' | ||
| import { ConfigService } from '../src/config/config.service' | ||
|
|
||
| export const mongodbInstance = new MongoMemoryServer() | ||
|
|
||
| /** | ||
| * A MongooseModule that creates a new ephemeral in-memory db for testing purposes. | ||
| * This module should be used instead of MyMongooseModule to allow concurrent testing - | ||
| * multiple independent in-memory db's can run at the same time. | ||
| */ | ||
| export const MockMongooseModule = MongooseModule.forRootAsync({ | ||
| imports: [ConfigModule], | ||
| useFactory: async () => { | ||
| await mongodbInstance.ensureInstance() | ||
| const uri = await mongodbInstance.getUri() | ||
| return { | ||
| uri, | ||
| } | ||
| }, | ||
| inject: [ConfigService], | ||
| }) |
This file contains hidden or 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,24 +1,82 @@ | ||
| import { INestApplication } from '@nestjs/common'; | ||
| import { Test } from '@nestjs/testing'; | ||
| import * as request from 'supertest'; | ||
| import { AppModule } from './../src/app.module'; | ||
| import { INestApplication } from '@nestjs/common' | ||
| import { Test } from '@nestjs/testing' | ||
| import request from 'supertest' | ||
| import { Identity } from '@kiltprotocol/sdk-js' | ||
| import { MockMongooseModule, mongodbInstance } from './MockMongooseModule' | ||
| import { AppModule } from '../src/app.module' | ||
|
|
||
| describe('AppController (e2e)', () => { | ||
| let app: INestApplication; | ||
| jest.mock( | ||
| '@kiltprotocol/sdk-js/build/blockchainApiConnection/BlockchainApiConnection' | ||
| ) | ||
| jest.mock('../src/mongoose/mongoose.module', () => ({ | ||
| MyMongooseModule: MockMongooseModule, | ||
| })) | ||
|
|
||
| describe('AppController availability (e2e)', () => { | ||
| let app: INestApplication | ||
|
|
||
| beforeAll(async () => { | ||
| const moduleFixture = await Test.createTestingModule({ | ||
| imports: [AppModule], | ||
| }).compile(); | ||
| }).compile() | ||
|
|
||
| app = moduleFixture.createNestApplication(); | ||
| await app.init(); | ||
| }); | ||
| app = moduleFixture.createNestApplication() | ||
| await app.init() | ||
| }, 30000) | ||
|
|
||
| it('/ (GET)', () => { | ||
| it('root responds with 404 (GET)', () => { | ||
| return request(app.getHttpServer()) | ||
| .get('/') | ||
| .expect(200) | ||
| .expect('Hello World!'); | ||
| }); | ||
| }); | ||
| .expect(404) | ||
| }) | ||
|
|
||
| it('ctypes endpoint available (GET)', () => { | ||
| return request(app.getHttpServer()) | ||
| .get('/ctype') | ||
| .expect(200, []) | ||
| }) | ||
|
|
||
| it('contacts endpoint available (GET)', () => { | ||
| return request(app.getHttpServer()) | ||
| .get('/contacts') | ||
| .expect(200, []) | ||
| }) | ||
|
|
||
| it('outgoing messages enpoint available (POST)', async () => { | ||
| return request(app.getHttpServer()) | ||
| .post(`/messaging`) | ||
| .send({}) | ||
| .expect(400) | ||
| }) | ||
|
|
||
| it('message inbox endpoint available (GET)', async () => { | ||
| const idAlice = await Identity.buildFromURI('//Alice') | ||
| return request(app.getHttpServer()) | ||
| .get(`/messaging/inbox/${idAlice.address}`) | ||
| .expect(200, []) | ||
| }) | ||
|
|
||
| it('message outbox endpoint available (GET)', async () => { | ||
| const idAlice = await Identity.buildFromURI('//Alice') | ||
| return request(app.getHttpServer()) | ||
| .get(`/messaging/sent/${idAlice.address}`) | ||
| .expect(200, []) | ||
| }) | ||
|
|
||
| it('health enpoint available (GET)', () => { | ||
| return request(app.getHttpServer()) | ||
| .get('/health') | ||
| .expect(200, { status: 'ok', info: {} }) | ||
| }) | ||
|
|
||
| it('faucet endpoint available (POST)', async () => { | ||
| return request(app.getHttpServer()) | ||
| .post(`/faucet/drop`) | ||
| .send({}) | ||
| .expect(400) | ||
| }) | ||
|
|
||
| afterAll(async () => { | ||
| await Promise.all([app.close(), mongodbInstance.stop()]) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused import