forked from subquery/subql
-
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.
* add integration test and support run test in docker-compose * apply eslint to tests * run all tests in pr workflow * --abort-on-container-exit * remove --build by default * set moduleNameMapper * --forceExit * --detectOpenHandles
- Loading branch information
Showing
18 changed files
with
182 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
.github | ||
node_modules | ||
coverage | ||
deploy | ||
docs | ||
test/docker-compose.yaml | ||
test/Dockerfile |
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
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,55 @@ | ||
// Copyright 2020-2021 OnFinality Limited authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { Sequelize } from 'sequelize'; | ||
import { SubqueryRepo } from '../entities'; | ||
import { DbModule } from './db.module'; | ||
|
||
describe('DbModule', () => { | ||
let app: INestApplication; | ||
|
||
afterEach(async () => { | ||
return app?.close(); | ||
}); | ||
|
||
it('can connect to database', async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [ | ||
DbModule.forRoot({ | ||
host: process.env.DB_HOST ?? '127.0.0.1', | ||
port: process.env.DB_PORT ? Number(process.env.DB_PORT) : 5432, | ||
username: process.env.DB_USER ?? 'postgres', | ||
password: process.env.DB_PASS ?? 'postgres', | ||
database: process.env.DB_DATABASE ?? 'postgres', | ||
}), | ||
], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
await app.init(); | ||
const sequelize = app.get(Sequelize); | ||
await expect(sequelize.authenticate()).resolves.not.toThrow(); | ||
}); | ||
|
||
it('can load subquery model', async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [ | ||
DbModule.forRoot({ | ||
host: process.env.DB_HOST ?? '127.0.0.1', | ||
port: process.env.DB_PORT ? Number(process.env.DB_PORT) : 5432, | ||
username: process.env.DB_USER ?? 'postgres', | ||
password: process.env.DB_PASS ?? 'postgres', | ||
database: process.env.DB_DATABASE ?? 'postgres', | ||
}), | ||
DbModule.forFeature(['Subquery']), | ||
], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
await app.init(); | ||
const subqueryRepo: SubqueryRepo = app.get('Subquery'); | ||
await expect(subqueryRepo.describe()).resolves.toBeTruthy(); | ||
}); | ||
}); |
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,41 @@ | ||
// Copyright 2020-2021 OnFinality Limited authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { SubqueryProject } from '../configure/project.model'; | ||
import { ApiService } from './api.service'; | ||
|
||
function testSubqueryProject(): SubqueryProject { | ||
const project = new SubqueryProject(); | ||
project.network = { | ||
endpoint: 'wss://polkadot.api.onfinality.io/public-ws', | ||
customTypes: { | ||
TestType: 'u32', | ||
}, | ||
}; | ||
return project; | ||
} | ||
|
||
describe('ApiService', () => { | ||
let app: INestApplication; | ||
|
||
afterEach(async () => { | ||
return app?.close(); | ||
}); | ||
|
||
it('can instantiate api', async () => { | ||
const module = await Test.createTestingModule({ | ||
providers: [ | ||
{ provide: SubqueryProject, useFactory: testSubqueryProject }, | ||
ApiService, | ||
], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
await app.init(); | ||
const apiService = app.get(ApiService); | ||
const api = await apiService.getApi(); | ||
expect(api.registry.getDefinition('TestType')).toEqual('u32'); | ||
}); | ||
}); |
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,5 @@ | ||
FROM node:14 | ||
WORKDIR /workdir | ||
|
||
COPY . . | ||
RUN yarn |
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,28 @@ | ||
version: '3' | ||
|
||
services: | ||
postgres: | ||
image: postgres:12-alpine | ||
ports: | ||
- 5432:5432 | ||
environment: | ||
POSTGRES_PASSWORD: postgres | ||
|
||
test: | ||
build: | ||
context: .. | ||
dockerfile: test/Dockerfile | ||
volumes: | ||
- ../coverage:/workdir/coverage | ||
depends_on: | ||
- "postgres" | ||
environment: | ||
DB_USER: postgres | ||
DB_PASS: postgres | ||
DB_DATABASE: postgres | ||
DB_HOST: postgres | ||
DB_POST: 5432 | ||
command: | ||
- yarn | ||
- test:all | ||
|
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,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": [ | ||
"**/node_modules/**", | ||
"**/*.spec.ts", | ||
"**/*.test.ts" | ||
] | ||
} |