This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration tests for services (#72)
KILTprotocol/ticket#617 adds integration tests that perform various calls to all service endpoints, using in-memory db for testing - availability tests for all endpoints - integration tests for all available requests against - messaging service - ctype registry - faucet service - contact repository
- Loading branch information
1 parent
8bdaa55
commit 48d2057
Showing
16 changed files
with
1,675 additions
and
27 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,5 @@ | ||
BOOT_NODE_ADDRESS=ws://127.0.0.1:9944 | ||
MONGODB_HOST=localhost | ||
MONGODB_USER='' | ||
MONGODB_PASS='' | ||
SECRET=thisIsASecret |
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
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,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 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.