Skip to content

Commit e1c48a0

Browse files
committed
feat: delete inactivated users
* tests
1 parent 9d22337 commit e1c48a0

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* eslint-disable promise/always-return, no-prototype-builtins */
2+
const { inspectPromise } = require('@makeomatic/deploy');
3+
const Promise = require('bluebird');
4+
const { expect } = require('chai');
5+
const faker = require('faker');
6+
const ld = require('lodash');
7+
8+
const simpleDispatcher = require('./../helpers/simpleDispatcher');
9+
10+
const { cleanUsers } = require('../../src/utils/inactiveUsers');
11+
const { createOrganization } = require('../helpers/organization');
12+
13+
const delay = fn => Promise.delay(1000).then(fn);
14+
15+
describe('#inactive user', function registerSuite() {
16+
beforeEach(global.startService);
17+
afterEach(global.clearRedis);
18+
19+
const regUser = {
20+
username: 'v@makeomatic.ru',
21+
audience: 'matic.ninja',
22+
alias: 'bondthebest',
23+
activate: false,
24+
metadata: {
25+
service: 'craft',
26+
},
27+
// eslint-disable-next-line max-len
28+
sso: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJtcy11c2VycyIsInByb2ZpbGUiOnsiZDEiOjEyLCJubSI6InBhaiJ9LCJpbnRlcm5hbHMiOnsidWlkIjoxNTE2MjM5MDIyfSwicHJvdmlkZXIiOiJmYWNlYm9vayIsInVpZCI6MTUxNjIzOTAyMiwidXNlcm5hbWUiOiJmb29AYmFyLmJheiJ9.QXLcP-86A3ly-teJt_C_XQo3hFUVC0pVALb84Eitozo',
29+
};
30+
31+
const regUserNoAlias = {
32+
username: 'v2@makeomatic.ru',
33+
audience: 'matic.log',
34+
activate: false,
35+
metadata: {
36+
service: 'log',
37+
},
38+
};
39+
40+
beforeEach(async function pretest() {
41+
this.users.config.deleteInactiveAccounts = 1;
42+
await createOrganization.call(this);
43+
await simpleDispatcher(this.users.router)('users.register', { ...regUser });
44+
return simpleDispatcher(this.users.router)('users.register', { ...regUserNoAlias });
45+
});
46+
47+
it('deletes inactive user', function test() {
48+
return delay(() => {
49+
return cleanUsers.call(this.users)
50+
.then(async (res) => {
51+
expect(res).to.be.eq(2);
52+
53+
const { username } = regUser;
54+
const dispatcher = simpleDispatcher(this.users.router);
55+
56+
await dispatcher('users.getInternalData', { username })
57+
.reflect()
58+
.then(inspectPromise(false));
59+
});
60+
});
61+
});
62+
63+
it('removes org member if user not passed activation', async function test() {
64+
const opts = {
65+
organizationId: this.organization.id,
66+
member: {
67+
email: regUser.username,
68+
firstName: faker.name.firstName(),
69+
lastName: faker.name.lastName(),
70+
},
71+
};
72+
73+
await this.dispatch('users.organization.members.add', opts);
74+
75+
return delay(() => {
76+
return cleanUsers.call(this.users)
77+
.then(() => {
78+
const dispatcher = simpleDispatcher(this.users.router);
79+
const reqOpts = {
80+
organizationId: this.organization.id,
81+
};
82+
83+
return dispatcher('users.organization.members.list', reqOpts)
84+
.reflect()
85+
.then(inspectPromise(true))
86+
.then(({ data }) => {
87+
const { attributes } = data;
88+
const membersWithUsername = ld.filter(attributes, (record) => {
89+
return record.id === regUser.username;
90+
});
91+
expect(membersWithUsername.length).to.be.eq(0);
92+
});
93+
});
94+
});
95+
});
96+
});

test/suites/updateMetadata.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ describe('#updateMetadata', function getMetadataSuite() {
6464
$incr: {
6565
b: 2,
6666
},
67+
$remove: ['c'],
6768
},
6869
{
6970
$incr: {
@@ -106,4 +107,35 @@ describe('#updateMetadata', function getMetadataSuite() {
106107
]);
107108
});
108109
});
110+
111+
it('must be able to run dynamic scripts / namespace fully available', function test() {
112+
const dispatch = simpleDispatcher(this.users.router);
113+
const lua = `
114+
local t = {}
115+
table.insert(t, "foo")
116+
local jsonDec = cjson.decode('{"bar": 1}')
117+
local typeCheck = type(t)
118+
return {jsonDec.bar, redis.call("TIME"), typeCheck, unpack(t)}
119+
`;
120+
121+
const params = {
122+
username,
123+
audience: [audience],
124+
script: {
125+
check: {
126+
lua,
127+
argv: ['nom-nom'],
128+
},
129+
},
130+
};
131+
132+
return dispatch('users.updateMetadata', params)
133+
.reflect()
134+
.then(inspectPromise())
135+
.then(({ check }) => {
136+
const [jsonVal, redisTime] = check;
137+
expect(jsonVal).to.be.eq(1);
138+
expect(redisTime).to.be.an('array');
139+
});
140+
});
109141
});

0 commit comments

Comments
 (0)