Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write tests for Project API Endpoint #18 #28

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 197 additions & 1 deletion packages/api-gateway/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,202 @@ beforeEach(async () => {
// describe('Project Creation Routes', () => {});
describe('Auth Routes', () => {
it('Returns empty value', async () => {
request(app.getHttpServer()).get('/auth').expect(200).expect('');
await request(app.getHttpServer()).get('/auth').expect(200).expect('');
});
});

describe('Project Creation Routes', () => {
it('Create a project with valid inputs', async () => {
await request(app.getHttpServer())
.post('/project')
.send({
name: 'testProject',
})
.expect(201)
.expect('');
});

it('Create a project with empty-string name', async () => {
await request(app.getHttpServer())
.post('/project')
.send({
name: '',
})
.expect(400)
.expect(
'{"message":["name should not be empty"],"error":"Bad Request","statusCode":400}',
);
});

it('Create a project with no name field', async () => {
await request(app.getHttpServer())
.post('/project')
.send({})
.expect(400)
.expect(
'{"message":["name should not be empty"],"error":"Bad Request","statusCode":400}',
);
});

it('Create a project with null name', async () => {
await request(app.getHttpServer())
.post('/project')
.send({
name: null,
})
.expect(400)
.expect(
'{"message":["name should not be empty"],"error":"Bad Request","statusCode":400}',
);
});

it('Create a project with non-string name', async () => {
await request(app.getHttpServer())
.post('/project')
.send({
name: 1,
})
.expect(201)
.expect('');
});
});

describe('Project Retrieval Routes', () => {
it('Get project with valid id', async () => {
await request(app.getHttpServer())
.get('/project/id/1')
.expect(200)
.then((response) => {
expect(response.body.name).toEqual('testProject');
expect(response.body.id).toEqual(1);
});
});

it('Get project with valid name', async () => {
await request(app.getHttpServer())
.get('/project/name/testProject')
.expect(200)
.then((response) => {
expect(response.body.name).toEqual('testProject');
expect(response.body.id).toEqual(1);
});
});

it('Get project with non-number id', async () => {
await request(app.getHttpServer())
.get('/project/id/abc')
.expect(400)
.expect('{"statusCode":400,"message":"id must be a number"}');
});

// it('Get project with non-existent id', async () => {
// await request(app.getHttpServer())
// .get('/project/id/0')
// .expect(400)
// .expect('{"statusCode":400,"message":"id does not exist"}')
// });

// it('Get project with non-existent name', async () => {
// await request(app.getHttpServer())
// .get('/project/name/abc')
// .expect(400)
// .expect('{"statusCode":400,"message":"name does not exist"}')
// });
});

describe('Project Update Routes', () => {
beforeAll(async () => {
await request(app.getHttpServer()).post('/user').send({
id: '1',
password: '1234',
name: 'Test User',
email: 'test@user.com',
});
});

it('Link user with project id using valid user id input', async () => {
await request(app.getHttpServer())
.put('/project/id/1/user')
.send({
id: '1',
})
.expect(200);
});

it('Link user with project id using valid user email input', async () => {
await request(app.getHttpServer())
.put('/project/id/1/user')
.send({
email: 'test@user.com',
})
.expect(200);
});

it('Link user with project id using non-number project id param', async () => {
await request(app.getHttpServer())
.put('/project/id/abc/user')
.send({
email: 'test@user.com',
})
.expect(400)
.expect('{"statusCode":400,"message":"id must be a number"}');
});

// it('Link user with project id using non-number user id input', async () => {
// await request(app.getHttpServer())
// .put('/project/id/1/user')
// .send({
// id: 'abc',
// })
// .expect(400)
// .expect('{"statusCode":400,"message":"id must be a number"}');
// });

// it('Link user with project id using invalid user email input', async () => {
// await request(app.getHttpServer())
// .put('/project/id/1/user')
// .send({
// email: 'abc',
// })
// .expect(400)
// .expect('');
// });

it('Link user with project name using valid user id input', async () => {
await request(app.getHttpServer())
.put('/project/name/testProject/user')
.send({
id: '1',
})
.expect(200);
});

it('Link user with project name using valid user email input', async () => {
await request(app.getHttpServer())
.put('/project/name/testProject/user')
.send({
email: 'test@user.com',
})
.expect(200);
});

// it('Link user with project name using non-number user id input', async () => {
// await request(app.getHttpServer())
// .put('/project/name/testProject/user')
// .send({
// id: 'abc',
// })
// .expect(400)
// .expect('{"statusCode":400,"message":"id must be a number"}');
// });

// it('Link user with project name using invalid user email input', async () => {
// await request(app.getHttpServer())
// .put('/project/name/testProject/user')
// .send({
// email: 'abc',
// })
// .expect(400)
// .expect('');
// });
});
Loading