From 17f8ef0d9b8e7cfefb0173ce99d67d62fd47bf16 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Tue, 16 Jan 2024 18:22:14 +0100 Subject: [PATCH] fix: tests and logging --- .../server/controllers/auth.js | 2 -- .../validation/__tests__/auth.test.js | 24 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/plugins/users-permissions/server/controllers/auth.js b/packages/plugins/users-permissions/server/controllers/auth.js index 2ac44e5b27..1b2036d3e8 100644 --- a/packages/plugins/users-permissions/server/controllers/auth.js +++ b/packages/plugins/users-permissions/server/controllers/auth.js @@ -338,7 +338,6 @@ module.exports = { } } - console.log('params', params); const newUser = { ...params, role: role.id, @@ -351,7 +350,6 @@ module.exports = { const sanitizedUser = await sanitizeUser(user, ctx); - console.log('sanitizedUser', sanitizedUser); if (settings.email_confirmation) { try { await getService('user').sendConfirmationEmail(sanitizedUser); diff --git a/packages/plugins/users-permissions/server/controllers/validation/__tests__/auth.test.js b/packages/plugins/users-permissions/server/controllers/validation/__tests__/auth.test.js index b8e03a1855..1e255cc546 100644 --- a/packages/plugins/users-permissions/server/controllers/validation/__tests__/auth.test.js +++ b/packages/plugins/users-permissions/server/controllers/validation/__tests__/auth.test.js @@ -15,7 +15,7 @@ const mockStrapi = { get: jest.fn(() => { return { register: { - allowedFields: [], + // only set allowedFields on a per-test basis }, }; }), @@ -74,7 +74,7 @@ describe('user-permissions auth', () => { }); describe('register', () => { - test('accepts valid body', async () => { + test('accepts valid registration', async () => { const ctx = { state: { auth: {}, @@ -89,7 +89,8 @@ describe('user-permissions auth', () => { expect(ctx.send).toHaveBeenCalledTimes(1); }); - test("throws ValidationError when given fields that aren't allowed", async () => { + test('throws ValidationError when passed fields not in allowedFields', async () => { + // without allowedFields const ctx = { state: { auth: {}, @@ -106,6 +107,22 @@ describe('user-permissions auth', () => { }; await expect(auth.register(ctx)).rejects.toThrow(errors.ValidationError); + // with allowedFields [] + global.strapi = { + ...mockStrapi, + config: { + get: jest.fn(() => { + return { + register: { + allowedFields: [], + }, + }; + }), + }, + }; + + await expect(auth.register(ctx)).rejects.toThrow(errors.ValidationError); + expect(ctx.send).toHaveBeenCalledTimes(0); }); @@ -122,6 +139,7 @@ describe('user-permissions auth', () => { }), }, }; + const ctx = { state: { auth: {},