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

Change status code for POST with user already in database #137

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion services/user-service/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ indexRouter.post("/", function (req: express.Request, res: express.Response) {
.createUser(req.body)
.then((result) => {
if (result === null) {
res.status(400).append("Is-User-Already-Found", "true").end();
res.status(200).append("Is-User-Already-Found", "true").end();
} else {
res.status(201).json(result);
}
Expand Down
6 changes: 3 additions & 3 deletions services/user-service/systemtest/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const updatePayload = { matchDifficulty: 1 };

describe('/index', () => {
describe('Sample App Workflow', () => {
it('Step 1: Add user 1 to database should pass', async () => {
it('Step 1: Add user 1 to database should pass with status 201', async () => {
// The function being tested
const response = await request(app).post('/api/user-service').send(fullNewUser);
expect(response.status).toStrictEqual(201);
Expand Down Expand Up @@ -42,9 +42,9 @@ describe('/index', () => {
expect(response.body).toStrictEqual(updatedNewUser);
})

it('Step 5: Attempt to add duplicate user 1 to database should fail with error', async () => {
it('Step 5: Attempt to add duplicate user 1 to database should give status 200', async () => {
const response = await request(app).post('/api/user-service').send(fullNewUser);
expect(response.status).toStrictEqual(400);
expect(response.status).toStrictEqual(200);
})

it('Step 6: Delete user 1 from database', async () => {
Expand Down
2 changes: 1 addition & 1 deletion services/user-service/test/routes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('/index', () => {

// The function being tested
const response = await request(app).post('/').send(fullNewUser);
expect(response.status).toStrictEqual(400);
expect(response.status).toStrictEqual(200);
})

it('[POST] to / when database is unavailable', async () => {
Expand Down