Skip to content
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
33 changes: 33 additions & 0 deletions packages/core/admin/server/controllers/__tests__/user.test.js
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion packages/core/admin/server/tests/admin-user.test.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ describe('Admin User CRUD (api)', () => {
method: 'GET',
qs: {
filters: {
email: testData.user.email,
username: testData.user.username,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const createPermissionChecker =

// Sanitized queries shortcuts
Object.keys(ACTIONS).forEach((action) => {
sanitizedQuery[action] = (query) => sanitizedQuery(query, action);
sanitizedQuery[action] = (query) => sanitizedQuery(query, ACTIONS[action]);
});

// Permission utils shortcuts
Expand Down
5 changes: 4 additions & 1 deletion packages/core/strapi/tests/api/fields/fields.test.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const data = { product: [] };

const getProductDataFields = (fields) => {
return data.product.map((product) => {
return { ...product, attributes: _.pick(product.attributes, fields) };
return {
...product,
attributes: fields.length > 0 ? _.pick(product.attributes, fields) : product.attributes,
};
});
};

Expand Down
3 changes: 1 addition & 2 deletions packages/plugins/graphql/server/services/builders/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { entries, mapValues, omit } = require('lodash/fp');
const { idArg, nonNull } = require('nexus');
const {
pagination: { withDefaultPagination },
contentTypes: { hasDraftAndPublish },
Expand Down Expand Up @@ -38,7 +37,7 @@ module.exports = ({ strapi }) => {
// Collection Types
if (kind === 'collectionType') {
if (!multiple) {
return { id: nonNull(idArg()) };
return { id: 'ID' };
}

const params = {
Expand Down