Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin committed Mar 15, 2023
1 parent eca2c57 commit 18fbe66
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/core/admin/server/controllers/__tests__/user.test.js
Expand Up @@ -174,13 +174,29 @@ describe('User Controller', () => {
pagination,
}));

const state = {
userAbility: {
can: jest.fn(),
cannot: jest.fn(() => false),
},
};

const sanitizeUser = jest.fn((user) => user);
const ctx = createContext({});
ctx.state = state;

const createPermissionsManager = jest.fn(() => ({
ability: state.userAbility,
sanitizeQuery: (query) => query,
}));

global.strapi = {
admin: {
services: {
user: { findPage, sanitizeUser },
permission: {
createPermissionsManager,
},
},
},
};
Expand All @@ -199,13 +215,30 @@ describe('User Controller', () => {
pagination,
}));

const state = {
userAbility: {
can: jest.fn(),
cannot: jest.fn(() => false),
},
};

const sanitizeUser = jest.fn((user) => user);
const ctx = createContext({ query: { _q: 'foo' } });

ctx.state = state;

const createPermissionsManager = jest.fn(() => ({
ability: state.userAbility,
sanitizeQuery: (query) => query,
}));

global.strapi = {
admin: {
services: {
user: { findPage, sanitizeUser },
permission: {
createPermissionsManager,
},
},
},
};
Expand Down
Expand Up @@ -23,6 +23,9 @@ describe('Single Types', () => {
create: jest.fn(() => false),
},
buildReadQuery: jest.fn((query) => query),
sanitizedQuery: {
read: (q) => q,
},
};

global.strapi = {
Expand Down Expand Up @@ -101,6 +104,9 @@ describe('Single Types', () => {
sanitizeCreateInput: (obj) => obj,
sanitizeOutput: (obj) => obj,
buildReadQuery: jest.fn((query) => query),
sanitizedQuery: {
update: (q) => q,
},
};

const createFn = jest.fn(() => ({}));
Expand Down Expand Up @@ -215,6 +221,9 @@ describe('Single Types', () => {
},
sanitizeOutput: jest.fn((obj) => obj),
buildReadQuery: jest.fn((query) => query),
sanitizedQuery: {
delete: (q) => q,
},
};

const deleteFn = jest.fn(() => ({}));
Expand Down Expand Up @@ -309,6 +318,9 @@ describe('Single Types', () => {
},
sanitizeOutput: jest.fn((obj) => obj),
buildReadQuery: jest.fn((query) => query),
sanitizedQuery: {
publish: (q) => q,
},
};

const publishFn = jest.fn(() => ({}));
Expand Down Expand Up @@ -403,6 +415,9 @@ describe('Single Types', () => {
},
sanitizeOutput: jest.fn((obj) => obj),
buildReadQuery: jest.fn((query) => query),
sanitizedQuery: {
unpublish: (q) => q,
},
};

const unpublishFn = jest.fn(() => ({}));
Expand Down

0 comments on commit 18fbe66

Please sign in to comment.