Skip to content

Commit

Permalink
feat: delete inactivated users
Browse files Browse the repository at this point in the history
    * tests
  • Loading branch information
pajgo committed Aug 23, 2019
1 parent ee23933 commit b43a1f4
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
96 changes: 96 additions & 0 deletions test/suites/deleteInactivatedUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* eslint-disable promise/always-return, no-prototype-builtins */
const { inspectPromise } = require('@makeomatic/deploy');
const Promise = require('bluebird');
const { expect } = require('chai');
const faker = require('faker');
const ld = require('lodash');

const simpleDispatcher = require('./../helpers/simpleDispatcher');

const { cleanUsers } = require('../../src/utils/inactiveUsers');
const { createOrganization } = require('../helpers/organization');

const delay = fn => Promise.delay(1000).then(fn);

describe('#inactive user', function registerSuite() {
beforeEach(global.startService);
afterEach(global.clearRedis);

const regUser = {
username: '[email protected]',
audience: 'matic.ninja',
alias: 'bondthebest',
activate: false,
metadata: {
service: 'craft',
},
// eslint-disable-next-line max-len
sso: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJtcy11c2VycyIsInByb2ZpbGUiOnsiZDEiOjEyLCJubSI6InBhaiJ9LCJpbnRlcm5hbHMiOnsidWlkIjoxNTE2MjM5MDIyfSwicHJvdmlkZXIiOiJmYWNlYm9vayIsInVpZCI6MTUxNjIzOTAyMiwidXNlcm5hbWUiOiJmb29AYmFyLmJheiJ9.QXLcP-86A3ly-teJt_C_XQo3hFUVC0pVALb84Eitozo',
};

const regUserNoAlias = {
username: '[email protected]',
audience: 'matic.log',
activate: false,
metadata: {
service: 'log',
},
};

beforeEach(async function pretest() {
this.users.config.deleteInactiveAccounts = 1;
await createOrganization.call(this);
await simpleDispatcher(this.users.router)('users.register', { ...regUser });
return simpleDispatcher(this.users.router)('users.register', { ...regUserNoAlias });
});

it('deletes inactive user', function test() {
return delay(() => {
return cleanUsers.call(this.users)
.then(async (res) => {
expect(res).to.be.eq(2);

const { username } = regUser;
const dispatcher = simpleDispatcher(this.users.router);

await dispatcher('users.getInternalData', { username })
.reflect()
.then(inspectPromise(false));
});
});
});

it('removes org member if user not passed activation', async function test() {
const opts = {
organizationId: this.organization.id,
member: {
email: regUser.username,
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
},
};

await this.dispatch('users.organization.members.add', opts);

return delay(() => {
return cleanUsers.call(this.users)
.then(() => {
const dispatcher = simpleDispatcher(this.users.router);
const reqOpts = {
organizationId: this.organization.id,
};

return dispatcher('users.organization.members.list', reqOpts)
.reflect()
.then(inspectPromise(true))
.then(({ data }) => {
const { attributes } = data;
const membersWithUsername = ld.filter(attributes, (record) => {
return record.id === regUser.username;
});
expect(membersWithUsername.length).to.be.eq(0);
});
});
});
});
});
32 changes: 32 additions & 0 deletions test/suites/updateMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('#updateMetadata', function getMetadataSuite() {
$incr: {
b: 2,
},
$remove: ['c'],
},
{
$incr: {
Expand Down Expand Up @@ -106,4 +107,35 @@ describe('#updateMetadata', function getMetadataSuite() {
]);
});
});

it('must be able to run dynamic scripts / namespace fully available', function test() {
const dispatch = simpleDispatcher(this.users.router);
const lua = `
local t = {}
table.insert(t, "foo")
local jsonDec = cjson.decode('{"bar": 1}')
local typeCheck = type(t)
return {jsonDec.bar, redis.call("TIME"), typeCheck, unpack(t)}
`;

const params = {
username,
audience: [audience],
script: {
check: {
lua,
argv: ['nom-nom'],
},
},
};

return dispatch('users.updateMetadata', params)
.reflect()
.then(inspectPromise())
.then(({ check }) => {
const [jsonVal, redisTime] = check;
expect(jsonVal).to.be.eq(1);
expect(redisTime).to.be.an('array');
});
});
});

0 comments on commit b43a1f4

Please sign in to comment.