-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function myDecorator(target: any, propertyKey: string, descriptor: PropertyDescriptor) { | ||
Check warning on line 1 in src/__test__/Decorators/decorators.ts GitHub Actions / build-lint-test-coverage
Check warning on line 1 in src/__test__/Decorators/decorators.ts GitHub Actions / build-lint-test-coverage
Check warning on line 1 in src/__test__/Decorators/decorators.ts GitHub Actions / build-lint-test-coverage
|
||
console.log("myDecorator called on: ", target, propertyKey, descriptor); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,72 @@ | ||
import request from 'supertest'; | ||
import { app, server } from '../index'; // update this with the path to your app file | ||
|
||
|
||
import { createConnection, getConnection, getConnectionOptions } from 'typeorm'; | ||
import { User } from '../entities/User'; | ||
import { getRepository, Repository } from 'typeorm'; | ||
Check warning on line 7 in src/__test__/route.test.ts GitHub Actions / build-lint-test-coverage
Check warning on line 7 in src/__test__/route.test.ts GitHub Actions / build-lint-test-coverage
Check warning on line 7 in src/__test__/route.test.ts GitHub Actions / build-lint-test-coverage
|
||
import { mock, MockProxy } from 'jest-mock-extended'; | ||
Check warning on line 8 in src/__test__/route.test.ts GitHub Actions / build-lint-test-coverage
Check warning on line 8 in src/__test__/route.test.ts GitHub Actions / build-lint-test-coverage
Check warning on line 8 in src/__test__/route.test.ts GitHub Actions / build-lint-test-coverage
|
||
|
||
|
||
|
||
beforeAll(async () => { | ||
// Connect to the test database | ||
const connectionOptions = await getConnectionOptions(); | ||
await createConnection({ ...connectionOptions, name: 'testConnection' }); | ||
}); | ||
|
||
afterAll(async () => { | ||
await getConnection('testConnection').close(); | ||
server.close(); | ||
}); | ||
|
||
|
||
|
||
describe('GET /', () => { | ||
// afterAll(done => { | ||
// server.close(done); | ||
// }); | ||
it('This is a testing route that returns', done => { | ||
request(app) | ||
.get('/api/v1/status') | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.expect({ | ||
status: 'success', | ||
data: { | ||
code: 202, | ||
message: 'This is a testing route that returns: 201' | ||
} | ||
}, done); | ||
}); | ||
}); | ||
describe('POST /user/register', () => { | ||
it('should register a new user and then delete it', async () => { | ||
// Arrange | ||
const newUser = { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
password: 'password', | ||
gender: 'Male', | ||
phoneNumber: '1234567890', | ||
userType: 'Buyer', | ||
status: 'active', | ||
verified: true, | ||
photoUrl: 'https://example.com/photo.jpg', | ||
}; | ||
|
||
// Act | ||
const res = await request(app) | ||
.post('/user/register') | ||
.send(newUser); | ||
|
||
// Assert | ||
expect(res.status).toBe(201); | ||
expect(res.body).toEqual({ message: 'User registered successfully' }); | ||
|
||
it('responds with "Knights Ecommerce API"', done => { | ||
request(app).get('/').expect(200, 'Knights Ecommerce API', done); | ||
// Clean up: delete the test user | ||
const userRepository = getRepository(User); | ||
const user = await userRepository.findOne({ where: { email: newUser.email } }); | ||
if (user) { | ||
await userRepository.remove(user); | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
"type": "postgres", | ||
"host": `${process.env.TEST_DB_HOST}`, | ||
"port": `${process.env.TEST_DB_PORT}`, | ||
"username": `${process.env.TEST_DB_USER}`, | ||
"password": `${process.env.TEST_DB_PASS}`, | ||
"database": `${process.env.TEST_DB_NAME}`, | ||
"synchronize": true, | ||
"logging": false, | ||
"dropSchema": true, | ||
"entities": [ | ||
"src/entities/**/*.ts" | ||
], | ||
"migrations": [ | ||
"src/migrations/**/*.ts" | ||
], | ||
"subscribers": [ | ||
"src/subscribers/**/*.ts" | ||
], | ||
"cli": { | ||
"entitiesDir": "src/entities", | ||
"migrationsDir": "src/migrations", | ||
"subscribersDir": "src/subscribers" | ||
} | ||
}; |