mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Merge branch 'releases/v4' into v4/graphql-schema-generation-refactor
This commit is contained in:
commit
c7a0747f96
@ -87,7 +87,7 @@ describe('User Controller', () => {
|
||||
|
||||
await userController.findOne(ctx);
|
||||
|
||||
expect(findOne).toHaveBeenCalledWith({ id: user.id });
|
||||
expect(findOne).toHaveBeenCalledWith(user.id);
|
||||
expect(sanitizeUser).toHaveBeenCalledWith(user);
|
||||
expect(ctx.body).toStrictEqual({ data: user });
|
||||
});
|
||||
@ -108,7 +108,7 @@ describe('User Controller', () => {
|
||||
|
||||
await userController.findOne(ctx);
|
||||
|
||||
expect(findOne).toHaveBeenCalledWith({ id: fakeId });
|
||||
expect(findOne).toHaveBeenCalledWith(fakeId);
|
||||
expect(notFound).toHaveBeenCalledWith('User does not exist');
|
||||
});
|
||||
});
|
||||
|
||||
@ -59,7 +59,7 @@ module.exports = {
|
||||
async findOne(ctx) {
|
||||
const { id } = ctx.params;
|
||||
|
||||
const user = await getService('user').findOne({ id });
|
||||
const user = await getService('user').findOne(id);
|
||||
|
||||
if (!user) {
|
||||
return ctx.notFound('User does not exist');
|
||||
|
||||
@ -383,16 +383,18 @@ describe('User', () => {
|
||||
const defaults = { page: 1, pageSize: 100 };
|
||||
|
||||
beforeEach(() => {
|
||||
const fetchPage = jest.fn(({ page = defaults.page, pageSize = defaults.pageSize } = {}) => {
|
||||
return {
|
||||
results: Array.from({ length: pageSize }).map((_, i) => i + (page - 1) * pageSize),
|
||||
pagination: { page, pageSize, total: page * pageSize, pageCount: page },
|
||||
};
|
||||
});
|
||||
const findPage = jest.fn(
|
||||
(uid, { page = defaults.page, pageSize = defaults.pageSize } = {}) => {
|
||||
return {
|
||||
results: Array.from({ length: pageSize }).map((_, i) => i + (page - 1) * pageSize),
|
||||
pagination: { page, pageSize, total: page * pageSize, pageCount: page },
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
global.strapi = {
|
||||
query() {
|
||||
return { findPage: fetchPage };
|
||||
entityService: {
|
||||
findPage,
|
||||
},
|
||||
};
|
||||
});
|
||||
@ -428,7 +430,7 @@ describe('User', () => {
|
||||
const user = { firstname: 'Kai', lastname: 'Doe', email: 'kaidoe@email.com' };
|
||||
|
||||
beforeEach(() => {
|
||||
const findOne = jest.fn(({ where: { id } }) =>
|
||||
const findOne = jest.fn((uid, id) =>
|
||||
Promise.resolve(
|
||||
{
|
||||
1: user,
|
||||
@ -437,23 +439,23 @@ describe('User', () => {
|
||||
);
|
||||
|
||||
global.strapi = {
|
||||
query() {
|
||||
return { findOne };
|
||||
entityService: {
|
||||
findOne,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
test('Finds and returns a user by its ID', async () => {
|
||||
const input = { id: 1 };
|
||||
const res = await userService.findOne(input);
|
||||
const id = 1;
|
||||
const res = await userService.findOne(id);
|
||||
|
||||
expect(res).not.toBeNull();
|
||||
expect(res).toMatchObject(user);
|
||||
});
|
||||
|
||||
test('Fails to find a user with provided params', async () => {
|
||||
const input = { id: 27 };
|
||||
const res = await userService.findOne(input);
|
||||
const id = 27;
|
||||
const res = await userService.findOne(id);
|
||||
|
||||
expect(res).toBeNull();
|
||||
});
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { toLower } = require('lodash/fp');
|
||||
const { Strategy: LocalStrategy } = require('passport-local');
|
||||
|
||||
const createLocalStrategy = strapi => {
|
||||
@ -11,7 +12,7 @@ const createLocalStrategy = strapi => {
|
||||
},
|
||||
(email, password, done) => {
|
||||
return strapi.admin.services.auth
|
||||
.checkCredentials({ email, password })
|
||||
.checkCredentials({ email: toLower(email), password })
|
||||
.then(([error, user, message]) => done(error, user, message))
|
||||
.catch(error => done(error));
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const { defaults } = require('lodash/fp');
|
||||
const { stringIncludes } = require('@strapi/utils');
|
||||
const { createUser, hasSuperAdminRole } = require('../domain/user');
|
||||
const { password: passwordValidator } = require('../validation/common-validators');
|
||||
@ -103,7 +104,7 @@ const updateById = async (id, attributes) => {
|
||||
* @param {string} password - new password
|
||||
*/
|
||||
const resetPasswordByEmail = async (email, password) => {
|
||||
const user = await findOne({ email });
|
||||
const user = await strapi.query('admin::user').findOne({ where: { email }, populate: ['roles'] });
|
||||
|
||||
if (!user) {
|
||||
throw new Error(`User not found for email: ${email}`);
|
||||
@ -125,7 +126,7 @@ const resetPasswordByEmail = async (email, password) => {
|
||||
* @param {int|string} userId user's id to look for
|
||||
*/
|
||||
const isLastSuperAdminUser = async userId => {
|
||||
const user = await findOne({ id: userId }, ['roles']);
|
||||
const user = await findOne(userId);
|
||||
const superAdminRole = await getService('role').getSuperAdminWithUsersCount();
|
||||
|
||||
return superAdminRole.usersCount === 1 && hasSuperAdminRole(user);
|
||||
@ -180,8 +181,8 @@ const register = async ({ registrationToken, userInfo }) => {
|
||||
/**
|
||||
* Find one user
|
||||
*/
|
||||
const findOne = async (where = {}, populate = ['roles']) => {
|
||||
return strapi.query('admin::user').findOne({ where, populate });
|
||||
const findOne = async (id, populate = ['roles']) => {
|
||||
return strapi.entityService.findOne('admin::user', id, { populate });
|
||||
};
|
||||
|
||||
/** Find many users (paginated)
|
||||
@ -189,15 +190,8 @@ const findOne = async (where = {}, populate = ['roles']) => {
|
||||
* @returns {Promise<user>}
|
||||
*/
|
||||
const findPage = async (query = {}) => {
|
||||
const { page = 1, pageSize = 100, populate = ['roles'] } = query;
|
||||
|
||||
return strapi.query('admin::user').findPage({
|
||||
where: query.filters,
|
||||
_q: query._q,
|
||||
populate,
|
||||
page,
|
||||
pageSize,
|
||||
});
|
||||
const enrichedQuery = defaults({ populate: ['roles'] }, query);
|
||||
return strapi.entityService.findPage('admin::user', enrichedQuery);
|
||||
};
|
||||
|
||||
/** Delete a user
|
||||
|
||||
@ -193,8 +193,6 @@ describe('Publication State', () => {
|
||||
products = res.body.data.map(res => ({ id: res.id, ...res.attributes }));
|
||||
});
|
||||
|
||||
const getApiRef = id => data.product.find(product => product.id === id);
|
||||
|
||||
test('Payload integrity', () => {
|
||||
expect(products).toHaveLength(lengthFor(contentTypes.product.name));
|
||||
});
|
||||
@ -205,27 +203,31 @@ describe('Publication State', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('First level (categories)', () => {
|
||||
products.forEach(({ id, categories }) => {
|
||||
const length = getApiRef(id).categories.filter(c => c.publishedAt !== null).length;
|
||||
expect(categories).toHaveLength(length);
|
||||
// const getApiRef = id => data.product.find(product => product.id === id);
|
||||
|
||||
categories.forEach(category => {
|
||||
expect(category.publishedAt).toBeISODate();
|
||||
});
|
||||
});
|
||||
});
|
||||
test.todo('First level (categories)');
|
||||
|
||||
test('Second level through component (countries)', () => {
|
||||
products.forEach(({ id, comp: { countries } }) => {
|
||||
const length = getApiRef(id).comp.countries.filter(c => c.publishedAt !== null).length;
|
||||
expect(countries).toHaveLength(length);
|
||||
// products.forEach(({ id, categories }) => {
|
||||
// const length = getApiRef(id).categories.filter(c => c.publishedAt !== null).length;
|
||||
// expect(categories).toHaveLength(length);
|
||||
|
||||
countries.forEach(country => {
|
||||
expect(country.publishedAt).toBeISODate();
|
||||
});
|
||||
});
|
||||
});
|
||||
// categories.forEach(category => {
|
||||
// expect(category.publishedAt).toBeISODate();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
test.todo('Second level through component (countries)');
|
||||
|
||||
// products.forEach(({ id, comp: { countries } }) => {
|
||||
// const length = getApiRef(id).comp.countries.filter(c => c.publishedAt !== null).length;
|
||||
// expect(countries).toHaveLength(length);
|
||||
|
||||
// countries.forEach(country => {
|
||||
// expect(country.publishedAt).toBeISODate();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ const _ = require('lodash');
|
||||
const createUtils = strapi => {
|
||||
const login = async userInfo => {
|
||||
const sanitizedUserInfo = _.pick(userInfo, ['email', 'id']);
|
||||
const user = await strapi.admin.services.user.findOne(sanitizedUserInfo);
|
||||
const user = await strapi.query('admin::user').findOne({ where: sanitizedUserInfo });
|
||||
if (!user) {
|
||||
throw new Error('User not found');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user