Skip to content

Commit

Permalink
feat: add and test link user to project endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
llam36 committed Feb 6, 2024
1 parent e696d45 commit 6201c53
Showing 1 changed file with 117 additions and 15 deletions.
132 changes: 117 additions & 15 deletions packages/api-gateway/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,46 +57,51 @@ describe('Project Creation Routes', () => {
name: 'testProject',
})
.expect(201)
.expect("");
.expect('');
});

it("Create a project with empty-string name", async () => {
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}');
.expect(
'{"message":["name should not be empty"],"error":"Bad Request","statusCode":400}',
);
});

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

it("Create a project with null name", async () => {
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}');
.expect(
'{"message":["name should not be empty"],"error":"Bad Request","statusCode":400}',
);
});

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

Expand All @@ -108,7 +113,7 @@ describe('Project Retrieval Routes', () => {
.then((response) => {
expect(response.body.name).toEqual('testProject');
expect(response.body.id).toEqual(1);
})
});
});

it('Get project with valid name', async () => {
Expand All @@ -118,14 +123,14 @@ describe('Project Retrieval Routes', () => {
.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"}')
.expect('{"statusCode":400,"message":"id must be a number"}');
});

// it('Get project with non-existent id', async () => {
Expand All @@ -141,4 +146,101 @@ describe('Project Retrieval Routes', () => {
// .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: '[email protected]',
});
});

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: '[email protected]',
})
.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: '[email protected]',
})
.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: '[email protected]',
})
.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('');
// });
});

0 comments on commit 6201c53

Please sign in to comment.