This repository has been archived by the owner on Jun 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prefix version can now be overridden in production (#334)
* prefix version can now be overridden in production * Checked all data contracts, ready for major v0 release * added version.e2e.ts
- Loading branch information
Showing
7 changed files
with
103 additions
and
8 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
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,77 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { NestFastifyApplication } from '@nestjs/platform-fastify' | ||
import { newFastifyAdapter } from '@src/fastify' | ||
import { AppModule } from '@src/app.module' | ||
import { Test } from '@nestjs/testing' | ||
import { ConfigService } from '@nestjs/config' | ||
|
||
const container = new MasterNodeRegTestContainer() | ||
let app: NestFastifyApplication | ||
|
||
class VersionConfigService extends ConfigService { | ||
constructor (rpcUrl: string) { | ||
super({ | ||
defid: { | ||
url: rpcUrl | ||
}, | ||
version: 'v0', | ||
network: 'regtest', | ||
database: { | ||
provider: 'memory' | ||
} | ||
}) | ||
} | ||
} | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.generate(1) | ||
|
||
const url = await container.getCachedRpcUrl() | ||
const module = await Test.createTestingModule({ | ||
imports: [AppModule.forRoot('memory')] | ||
}) | ||
.overrideProvider(ConfigService).useValue(new VersionConfigService(url)) | ||
.compile() | ||
|
||
app = module.createNestApplication<NestFastifyApplication>( | ||
newFastifyAdapter({ logger: false }) | ||
) | ||
AppModule.configure(app) | ||
await app.init() | ||
}) | ||
|
||
afterAll(async () => { | ||
try { | ||
await app.close() | ||
} finally { | ||
await container.stop() | ||
} | ||
}) | ||
|
||
it('should GET /v0/regtest/tokens with overridden endpoint', async () => { | ||
const res = await app.inject({ | ||
method: 'GET', | ||
url: '/v0/regtest/tokens' | ||
}) | ||
|
||
expect(res.statusCode).toStrictEqual(200) | ||
expect(res.json()).toStrictEqual({ | ||
data: [ | ||
expect.objectContaining({ | ||
id: '0', | ||
symbol: 'DFI', | ||
symbolKey: 'DFI' | ||
}) | ||
] | ||
}) | ||
}) | ||
|
||
it('should fail GET with /v0.0/regtest/tokens as endpoint is overridden', async () => { | ||
const res = await app.inject({ | ||
method: 'GET', | ||
url: '/v0.0/regtest/tokens' | ||
}) | ||
|
||
expect(res.statusCode).toStrictEqual(404) | ||
}) |