it('should filter users', () => { return request(app) .get('/v1/users') .set('Authorization', `Bearer ${adminAccessToken}`) .query({ email: dbUsers.jonSnow.email }) .expect(httpStatus.OK) .then(async (res) => { delete dbUsers.jonSnow.password; const john = await format(dbUsers.jonSnow); // before comparing it is necessary to convert String to Date res.body[0].createdAt = new Date(res.body[0].createdAt); const includesjonSnow = some(res.body, john); expect(res.body).to.be.an('array'); expect(res.body).to.have.lengthOf(1); expect(includesjonSnow).to.be.true; }); });
it('should get all users', () => { return request(app) .get('/v1/users') .set('Authorization', `Bearer ${adminAccessToken}`) .expect(httpStatus.OK) .then(async (res) => { const bran = await format(dbUsers.branStark); const john = await format(dbUsers.jonSnow); // before comparing it is necessary to convert String to Date res.body[0].createdAt = new Date(res.body[0].createdAt); res.body[1].createdAt = new Date(res.body[1].createdAt); const includesBranStark = some(res.body, bran); const includesjonSnow = some(res.body, john); expect(res.body).to.be.an('array'); expect(res.body).to.have.lengthOf(2); expect(includesBranStark).to.be.true; expect(includesjonSnow).to.be.true; }); });
const ensureLinkIsUnique = (req, res, next) => { const newLink = req.entity const otherClientId = newLink.clientId1 === req.params.clientId ? newLink.clientId2 : newLink.clientId1 const linkRepo = new ClientLinkRepository(req.database) linkRepo.getLinksForClientId(req.params.clientId) .then(links => { if (some(links, link => link.clientId1 === otherClientId || link.clientId2 === otherClientId)) { return next({httpStatus: 400, message: 'This link already exists'}) } next() }) }
some(item => item !== undefined, [ this.state.usernameErrors, this.state.emailErrors, this.state.passwordErrors ])
/** * Checks whether or not the system knows about an instance * @param {Instance} instance */ hasInstance(instance) { const instances = this.globalConfig.get('instances', {}); return some(instances, ({cwd}, name) => cwd === instance.dir && name === instance.name); }
/** * Check if user has role * * @param name Name of the role * * @return {boolean} */ async is (name, params = {}) { const role = this.imperium._roles[name] /* istanbul ignore if */ if (!role) return false const processedRole = await role.process(this.ctx) if (!processedRole) return false if (typeof processedRole === 'boolean') return processedRole const processedRoles = Array.isArray(processedRole) ? processedRole : [processedRole] return some(processedRoles, (processedRoleParams) => { return this._matchActions(processedRoleParams, params) }) }
}); if (ext.startsWith('ts') && !some(loadedOptions.plugins, {key: 'transform-typescript'})) { return processedFiles;
/** * Check if processed role matches route action * The role is processed using the current route context (auth) * * @private * * @param role Role to check * @param routeAction Action required by the route * * @return {boolean} */ async _roleMatchRouteAction (role, routeAction) { const processedRole = await role.process(this.ctx) if (!processedRole) return false if (typeof processedRole === 'boolean') return processedRole const processedRoles = Array.isArray(processedRole) ? processedRole : [processedRole] return some(processedRoles, (params) => { const roleAction = { name: role.action.name } forIn(role.action.params, (value, key) => { if (value === '@') roleAction[key] = params[key] else roleAction[key] = value }) return this._matchActions(roleAction, routeAction) }) }
it('should get all customers with pagination', () => { return request(app) .get('/v1/customers') .set('Authorization', `Bearer ${adminAccessToken}`) .query({ page: 2, perPage: 1 }) .expect(httpStatus.OK) .then((res) => { delete dbCustomers.jhonDoe.password; const john = format(dbCustomers.jhonDoe); const includesjhonDoe = some(res.body, john); // before comparing it is necessary to convert String to Date res.body[0].createdAt = new Date(res.body[0].createdAt); expect(res.body).to.be.an('array'); expect(res.body).to.have.lengthOf(1); expect(includesjhonDoe).to.be.true; }); });
it('should filter customers', () => { return request(app) .get('/v1/customers') .set('Authorization', `Bearer ${adminAccessToken}`) .query({ email: dbCustomers.jhonDoe.email }) .expect(httpStatus.OK) .then((res) => { delete dbCustomers.jhonDoe.password; const john = format(dbCustomers.jhonDoe); const includesjhonDoe = some(res.body, john); // before comparing it is necessary to convert String to Date res.body[0].createdAt = new Date(res.body[0].createdAt); expect(res.body).to.be.an('array'); expect(res.body).to.have.lengthOf(1); expect(includesjhonDoe).to.be.true; }); });
it('should get all customers', () => { return request(app) .get('/v1/customers') .set('Authorization', `Bearer ${adminAccessToken}`) .expect(httpStatus.OK) .then(async (res) => { const bran = format(dbCustomers.masterAccount); const john = format(dbCustomers.jhonDoe); const includesmasterAccount = some(res.body, bran); const includesjhonDoe = some(res.body, john); // before comparing it is necessary to convert String to Date res.body[0].createdAt = new Date(res.body[0].createdAt); res.body[1].createdAt = new Date(res.body[1].createdAt); expect(res.body).to.be.an('array'); expect(res.body).to.have.lengthOf(3); expect(includesmasterAccount).to.be.true; expect(includesjhonDoe).to.be.true; }); });