Skip to content

Commit 1eb69b4

Browse files
authored
Merge pull request AgesEmpire#213 from Mac-5/features/integration-testing
Features/integration testing
2 parents ede0586 + 42d61a3 commit 1eb69b4

4 files changed

Lines changed: 115 additions & 0 deletions

File tree

test/fixtures/signals.fixture.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const signalFixture = (overrides = {}) => ({
2+
baseAsset: 'USDC',
3+
counterAsset: 'XLM',
4+
type: 'BUY',
5+
entryPrice: '0.095',
6+
targetPrice: '0.105',
7+
stopLossPrice: '0.090',
8+
confidenceScore: 85,
9+
rationale: 'Test signal rationale',
10+
...overrides,
11+
});
12+
13+
export const signalsFixture = () => [
14+
signalFixture({ baseAsset: 'USDC', counterAsset: 'XLM' }),
15+
signalFixture({ baseAsset: 'BTC', counterAsset: 'USDC', type: 'SELL' }),
16+
signalFixture({ baseAsset: 'ETH', counterAsset: 'USDC' }),
17+
];

test/fixtures/users.fixture.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const userFixture = (overrides = {}) => ({
2+
username: 'testuser',
3+
email: 'test@example.com',
4+
walletAddress: 'GABC123DEF456GHI789JKL012MNO345PQR678STU901VWX234YZA567BCD',
5+
displayName: 'Test User',
6+
...overrides,
7+
});
8+
9+
export const usersFixture = () => [
10+
userFixture({ username: 'user1', email: 'user1@example.com' }),
11+
userFixture({ username: 'user2', email: 'user2@example.com' }),
12+
userFixture({ username: 'user3', email: 'user3@example.com' }),
13+
];

test/helpers/test-app.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { Test, TestingModule } from '@nestjs/testing';
3+
import { TypeOrmModule } from '@nestjs/typeorm';
4+
import { ConfigModule } from '@nestjs/config';
5+
6+
export async function createTestApp(): Promise<INestApplication> {
7+
const moduleFixture: TestingModule = await Test.createTestingModule({
8+
imports: [
9+
ConfigModule.forRoot({
10+
isGlobal: true,
11+
envFilePath: '.env.test',
12+
}),
13+
TypeOrmModule.forRoot({
14+
type: 'postgres',
15+
host: process.env.TEST_DATABASE_HOST || 'localhost',
16+
port: parseInt(process.env.TEST_DATABASE_PORT || '5432'),
17+
username: process.env.TEST_DATABASE_USER || 'test',
18+
password: process.env.TEST_DATABASE_PASSWORD || 'test',
19+
database: process.env.TEST_DATABASE_NAME || 'stellarswipe_test',
20+
entities: ['src/**/*.entity.ts'],
21+
synchronize: true,
22+
dropSchema: true,
23+
}),
24+
],
25+
}).compile();
26+
27+
const app = moduleFixture.createNestApplication();
28+
app.setGlobalPrefix('api/v1');
29+
await app.init();
30+
return app;
31+
}
32+
33+
export async function getTestJWT(): Promise<string> {
34+
return 'test-jwt-token';
35+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import * as request from 'supertest';
3+
import { signalFixture } from '../fixtures/signals.fixture';
4+
import { createTestApp, getTestJWT } from '../helpers/test-app';
5+
6+
describe('Signals API (Integration)', () => {
7+
let app: INestApplication;
8+
let jwtToken: string;
9+
10+
beforeAll(async () => {
11+
app = await createTestApp();
12+
jwtToken = await getTestJWT();
13+
});
14+
15+
afterAll(async () => {
16+
await app.close();
17+
});
18+
19+
describe('POST /api/v1/signals', () => {
20+
it('should create a signal', async () => {
21+
return request(app.getHttpServer())
22+
.post('/api/v1/signals')
23+
.set('Authorization', `Bearer ${jwtToken}`)
24+
.send(signalFixture())
25+
.expect(201)
26+
.expect((res) => {
27+
expect(res.body.id).toBeDefined();
28+
});
29+
});
30+
31+
it('should reject invalid signal', async () => {
32+
return request(app.getHttpServer())
33+
.post('/api/v1/signals')
34+
.set('Authorization', `Bearer ${jwtToken}`)
35+
.send({ baseAsset: 'INVALID' })
36+
.expect(400);
37+
});
38+
});
39+
40+
describe('GET /api/v1/signals', () => {
41+
it('should return signals list', async () => {
42+
return request(app.getHttpServer())
43+
.get('/api/v1/signals')
44+
.expect(200)
45+
.expect((res) => {
46+
expect(Array.isArray(res.body)).toBe(true);
47+
});
48+
});
49+
});
50+
});

0 commit comments

Comments
 (0)