From 932317ad82ec1796306cbea07880c6da23b55f58 Mon Sep 17 00:00:00 2001 From: Tauri Date: Wed, 11 Mar 2026 09:00:56 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=C3=9Clesanne=202:=20Mocked=20API=20testid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.mock.test.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ app.test.js | 11 ----------- 2 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 app.mock.test.js diff --git a/app.mock.test.js b/app.mock.test.js new file mode 100644 index 0000000..c68d6c1 --- /dev/null +++ b/app.mock.test.js @@ -0,0 +1,46 @@ +jest.mock('./validation/validateEmail') + +const createApp = require('./app') +const request = require('supertest') +const validateUsername = require('./validation/validateUsername') +const validatePassword = require('./validation/validatePassword') +const validateEmail = require('./validation/validateEmail') + +const app = createApp(validateUsername, validatePassword, validateEmail) + +describe('given correct username and password', () => { + test('return status 200', async () => { + validateEmail.mockReturnValue(true) + + const response = await request(app).post('/users').send({ + username: 'Username', + password: 'Password123', + email: 'student@example.com' + }) + expect(response.statusCode).toBe(200) + }) + + test('returns userId', async () => { + validateEmail.mockReturnValue(true) + + const response = await request(app).post('/users').send({ + username: 'Username', + password: 'Password123', + email: 'student@example.com' + }) + expect(response.body.userId).toBeDefined(); + }) +}) + +describe('given incorrect or missing username and password', () => { + test('return status 400', async () => { + validateEmail.mockReturnValue(false) + + const response = await request(app).post('/users').send({ + username: 'user', + password: 'password', + email: 'not-an-email' + }) + expect(response.statusCode).toBe(400) + }) +}) diff --git a/app.test.js b/app.test.js index f1b561d..39a8893 100644 --- a/app.test.js +++ b/app.test.js @@ -24,11 +24,6 @@ describe('given correct username and password', () => { }) expect(response.body.userId).toBeDefined(); }) - - // test response content type? - // test response message - // test response user id value - // ... }) describe('given incorrect or missing username and password', () => { @@ -40,10 +35,4 @@ describe('given incorrect or missing username and password', () => { }) expect(response.statusCode).toBe(400) }) - - // test response message - // test that response does NOT have userId - // test incorrect username or password according to requirements - // test missing username or password - // ... }) \ No newline at end of file From 2a39b600206bb8a264da438cd26ca77b13fd10d1 Mon Sep 17 00:00:00 2001 From: Tauri Date: Wed, 11 Mar 2026 09:00:56 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=C3=9Clesanne=202:=20Mocked=20API=20testid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.mock.test.js | 2 +- app.test.js | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/app.mock.test.js b/app.mock.test.js index 79b9449..ed4fd1e 100644 --- a/app.mock.test.js +++ b/app.mock.test.js @@ -56,4 +56,4 @@ describe('given incorrect or missing username and password', () => { // test incorrect username or password according to requirements // test missing username or password // ... -}) \ No newline at end of file +}) diff --git a/app.test.js b/app.test.js index f1b561d..39a8893 100644 --- a/app.test.js +++ b/app.test.js @@ -24,11 +24,6 @@ describe('given correct username and password', () => { }) expect(response.body.userId).toBeDefined(); }) - - // test response content type? - // test response message - // test response user id value - // ... }) describe('given incorrect or missing username and password', () => { @@ -40,10 +35,4 @@ describe('given incorrect or missing username and password', () => { }) expect(response.statusCode).toBe(400) }) - - // test response message - // test that response does NOT have userId - // test incorrect username or password according to requirements - // test missing username or password - // ... }) \ No newline at end of file