fix: tests and logging

This commit is contained in:
Ben Irvin 2024-01-16 18:22:14 +01:00
parent 8263926b47
commit 17f8ef0d9b
2 changed files with 21 additions and 5 deletions

View File

@ -338,7 +338,6 @@ module.exports = {
} }
} }
console.log('params', params);
const newUser = { const newUser = {
...params, ...params,
role: role.id, role: role.id,
@ -351,7 +350,6 @@ module.exports = {
const sanitizedUser = await sanitizeUser(user, ctx); const sanitizedUser = await sanitizeUser(user, ctx);
console.log('sanitizedUser', sanitizedUser);
if (settings.email_confirmation) { if (settings.email_confirmation) {
try { try {
await getService('user').sendConfirmationEmail(sanitizedUser); await getService('user').sendConfirmationEmail(sanitizedUser);

View File

@ -15,7 +15,7 @@ const mockStrapi = {
get: jest.fn(() => { get: jest.fn(() => {
return { return {
register: { register: {
allowedFields: [], // only set allowedFields on a per-test basis
}, },
}; };
}), }),
@ -74,7 +74,7 @@ describe('user-permissions auth', () => {
}); });
describe('register', () => { describe('register', () => {
test('accepts valid body', async () => { test('accepts valid registration', async () => {
const ctx = { const ctx = {
state: { state: {
auth: {}, auth: {},
@ -89,7 +89,8 @@ describe('user-permissions auth', () => {
expect(ctx.send).toHaveBeenCalledTimes(1); 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 = { const ctx = {
state: { state: {
auth: {}, auth: {},
@ -106,6 +107,22 @@ describe('user-permissions auth', () => {
}; };
await expect(auth.register(ctx)).rejects.toThrow(errors.ValidationError); 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); expect(ctx.send).toHaveBeenCalledTimes(0);
}); });
@ -122,6 +139,7 @@ describe('user-permissions auth', () => {
}), }),
}, },
}; };
const ctx = { const ctx = {
state: { state: {
auth: {}, auth: {},