@pgpm/achievements 0.15.3 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +1 -1
- package/package.json +5 -5
- package/pgpm-achievements.control +1 -1
- package/__tests__/__snapshots__/achievements.test.ts.snap +0 -180
- package/__tests__/__snapshots__/triggers.test.ts.snap +0 -112
- package/__tests__/achievements.test.ts +0 -249
- package/__tests__/triggers.test.ts +0 -166
- /package/sql/{pgpm-achievements--0.15.2.sql → pgpm-achievements--0.15.3.sql} +0 -0
package/Makefile
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpm/achievements",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.4",
|
|
4
4
|
"description": "Achievement system for tracking user progress and milestones",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"test:watch": "jest --watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@pgpm/jwt-claims": "0.15.
|
|
25
|
-
"@pgpm/verify": "0.15.
|
|
24
|
+
"@pgpm/jwt-claims": "0.15.4",
|
|
25
|
+
"@pgpm/verify": "0.15.4"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"pgpm": "^1.
|
|
28
|
+
"pgpm": "^1.2.2"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/constructive-io/pgpm-modules/issues"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "aad0dbef0336d6c18d027120ef9addc418822edd"
|
|
39
39
|
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`advanced 1`] = `
|
|
4
|
-
{
|
|
5
|
-
"advancedRequirements": [
|
|
6
|
-
{
|
|
7
|
-
"id": "[ID]",
|
|
8
|
-
"level": "advanced",
|
|
9
|
-
"name": "invite_users",
|
|
10
|
-
"priority": 100,
|
|
11
|
-
"required_count": 12,
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
}
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
exports[`advanced 2`] = `
|
|
18
|
-
{
|
|
19
|
-
"newbieRequirements": [],
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
exports[`advanced 3`] = `
|
|
24
|
-
{
|
|
25
|
-
"newbie": {
|
|
26
|
-
"user_achieved": true,
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
exports[`advanced 4`] = `
|
|
32
|
-
{
|
|
33
|
-
"advanced": {
|
|
34
|
-
"user_achieved": false,
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
exports[`advanced part II 1`] = `
|
|
40
|
-
{
|
|
41
|
-
"advancedRequirements": [
|
|
42
|
-
{
|
|
43
|
-
"id": "[ID]",
|
|
44
|
-
"level": "advanced",
|
|
45
|
-
"name": "invite_users",
|
|
46
|
-
"priority": 100,
|
|
47
|
-
"required_count": 12,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"id": "[ID]",
|
|
51
|
-
"level": "advanced",
|
|
52
|
-
"name": "complete_action",
|
|
53
|
-
"priority": 100,
|
|
54
|
-
"required_count": 5,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"id": "[ID]",
|
|
58
|
-
"level": "advanced",
|
|
59
|
-
"name": "apply_for_verifier",
|
|
60
|
-
"priority": 100,
|
|
61
|
-
"required_count": 1,
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"id": "[ID]",
|
|
65
|
-
"level": "advanced",
|
|
66
|
-
"name": "create_action",
|
|
67
|
-
"priority": 100,
|
|
68
|
-
"required_count": 2,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
}
|
|
72
|
-
`;
|
|
73
|
-
|
|
74
|
-
exports[`advanced part II 2`] = `
|
|
75
|
-
{
|
|
76
|
-
"newbieRequirements": [],
|
|
77
|
-
}
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
|
-
exports[`advanced part II 3`] = `
|
|
81
|
-
{
|
|
82
|
-
"newbie": {
|
|
83
|
-
"user_achieved": true,
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
`;
|
|
87
|
-
|
|
88
|
-
exports[`advanced part II 4`] = `
|
|
89
|
-
{
|
|
90
|
-
"advanced": {
|
|
91
|
-
"user_achieved": false,
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
`;
|
|
95
|
-
|
|
96
|
-
exports[`advanced part III 1`] = `
|
|
97
|
-
{
|
|
98
|
-
"advancedRequirements": [],
|
|
99
|
-
}
|
|
100
|
-
`;
|
|
101
|
-
|
|
102
|
-
exports[`advanced part III 2`] = `
|
|
103
|
-
{
|
|
104
|
-
"newbieRequirements": [],
|
|
105
|
-
}
|
|
106
|
-
`;
|
|
107
|
-
|
|
108
|
-
exports[`advanced part III 3`] = `
|
|
109
|
-
{
|
|
110
|
-
"newbie": {
|
|
111
|
-
"user_achieved": true,
|
|
112
|
-
},
|
|
113
|
-
}
|
|
114
|
-
`;
|
|
115
|
-
|
|
116
|
-
exports[`advanced part III 4`] = `
|
|
117
|
-
{
|
|
118
|
-
"advanced": {
|
|
119
|
-
"user_achieved": true,
|
|
120
|
-
},
|
|
121
|
-
}
|
|
122
|
-
`;
|
|
123
|
-
|
|
124
|
-
exports[`newbie 1`] = `
|
|
125
|
-
{
|
|
126
|
-
"advancedRequirements": [
|
|
127
|
-
{
|
|
128
|
-
"id": "[ID]",
|
|
129
|
-
"level": "advanced",
|
|
130
|
-
"name": "invite_users",
|
|
131
|
-
"priority": 100,
|
|
132
|
-
"required_count": 15,
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
"id": "[ID]",
|
|
136
|
-
"level": "advanced",
|
|
137
|
-
"name": "complete_action",
|
|
138
|
-
"priority": 100,
|
|
139
|
-
"required_count": 12,
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
}
|
|
143
|
-
`;
|
|
144
|
-
|
|
145
|
-
exports[`newbie 2`] = `
|
|
146
|
-
{
|
|
147
|
-
"newbieRequirements": [
|
|
148
|
-
{
|
|
149
|
-
"id": "[ID]",
|
|
150
|
-
"level": "newbie",
|
|
151
|
-
"name": "upload_profile_image",
|
|
152
|
-
"priority": 100,
|
|
153
|
-
"required_count": 1,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
"id": "[ID]",
|
|
157
|
-
"level": "newbie",
|
|
158
|
-
"name": "complete_action",
|
|
159
|
-
"priority": 100,
|
|
160
|
-
"required_count": 2,
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
}
|
|
164
|
-
`;
|
|
165
|
-
|
|
166
|
-
exports[`newbie 3`] = `
|
|
167
|
-
{
|
|
168
|
-
"newbie": {
|
|
169
|
-
"user_achieved": false,
|
|
170
|
-
},
|
|
171
|
-
}
|
|
172
|
-
`;
|
|
173
|
-
|
|
174
|
-
exports[`newbie 4`] = `
|
|
175
|
-
{
|
|
176
|
-
"advanced": {
|
|
177
|
-
"user_achieved": false,
|
|
178
|
-
},
|
|
179
|
-
}
|
|
180
|
-
`;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`newbie 1`] = `
|
|
4
|
-
{
|
|
5
|
-
"beforeInsert": [],
|
|
6
|
-
}
|
|
7
|
-
`;
|
|
8
|
-
|
|
9
|
-
exports[`newbie 2`] = `
|
|
10
|
-
{
|
|
11
|
-
"afterFirstInsert": [
|
|
12
|
-
{
|
|
13
|
-
"count": 1,
|
|
14
|
-
"created_at": "[DATE]",
|
|
15
|
-
"id": "[ID]",
|
|
16
|
-
"name": "tg_achievement",
|
|
17
|
-
"user_id": "[ID]",
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
exports[`newbie 3`] = `
|
|
24
|
-
{
|
|
25
|
-
"afterUpdateToggleToValue": [
|
|
26
|
-
{
|
|
27
|
-
"count": 1,
|
|
28
|
-
"created_at": "[DATE]",
|
|
29
|
-
"id": "[ID]",
|
|
30
|
-
"name": "tg_achievement",
|
|
31
|
-
"user_id": "[ID]",
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"count": 1,
|
|
35
|
-
"created_at": "[DATE]",
|
|
36
|
-
"id": "[ID]",
|
|
37
|
-
"name": "tg_achievement_toggle",
|
|
38
|
-
"user_id": "[ID]",
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
exports[`newbie 4`] = `
|
|
45
|
-
{
|
|
46
|
-
"afterUpdateToggleToNull": [
|
|
47
|
-
{
|
|
48
|
-
"count": 1,
|
|
49
|
-
"created_at": "[DATE]",
|
|
50
|
-
"id": "[ID]",
|
|
51
|
-
"name": "tg_achievement",
|
|
52
|
-
"user_id": "[ID]",
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
exports[`newbie 5`] = `
|
|
59
|
-
{
|
|
60
|
-
"afterIsVerifiedIsTrue": [
|
|
61
|
-
{
|
|
62
|
-
"count": 1,
|
|
63
|
-
"created_at": "[DATE]",
|
|
64
|
-
"id": "[ID]",
|
|
65
|
-
"name": "tg_achievement",
|
|
66
|
-
"user_id": "[ID]",
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
"count": 1,
|
|
70
|
-
"created_at": "[DATE]",
|
|
71
|
-
"id": "[ID]",
|
|
72
|
-
"name": "tg_achievement_toggle_boolean",
|
|
73
|
-
"user_id": "[ID]",
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
}
|
|
77
|
-
`;
|
|
78
|
-
|
|
79
|
-
exports[`newbie 6`] = `
|
|
80
|
-
{
|
|
81
|
-
"afterIsVerifiedIsFalse": [
|
|
82
|
-
{
|
|
83
|
-
"count": 1,
|
|
84
|
-
"created_at": "[DATE]",
|
|
85
|
-
"id": "[ID]",
|
|
86
|
-
"name": "tg_achievement",
|
|
87
|
-
"user_id": "[ID]",
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
}
|
|
91
|
-
`;
|
|
92
|
-
|
|
93
|
-
exports[`newbie 7`] = `
|
|
94
|
-
{
|
|
95
|
-
"afterIsApprovedTrue": [
|
|
96
|
-
{
|
|
97
|
-
"count": 1,
|
|
98
|
-
"created_at": "[DATE]",
|
|
99
|
-
"id": "[ID]",
|
|
100
|
-
"name": "tg_achievement",
|
|
101
|
-
"user_id": "[ID]",
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
"count": 1,
|
|
105
|
-
"created_at": "[DATE]",
|
|
106
|
-
"id": "[ID]",
|
|
107
|
-
"name": "tg_achievement_boolean",
|
|
108
|
-
"user_id": "[ID]",
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
}
|
|
112
|
-
`;
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { getConnections, PgTestClient, snapshot } from 'pgsql-test';
|
|
2
|
-
|
|
3
|
-
let pg: PgTestClient;
|
|
4
|
-
let teardown: () => Promise<void>;
|
|
5
|
-
|
|
6
|
-
const user_id = 'b9d22af1-62c7-43a5-b8c4-50630bbd4962';
|
|
7
|
-
|
|
8
|
-
const repeat = (str: string, n: number): string[] =>
|
|
9
|
-
Array.from({ length: n }).map(() => str);
|
|
10
|
-
|
|
11
|
-
const levels = ['newbie', 'advanced'];
|
|
12
|
-
|
|
13
|
-
const newbie = [
|
|
14
|
-
['upload_profile_image'],
|
|
15
|
-
['complete_action', 5],
|
|
16
|
-
['accept_cookies'],
|
|
17
|
-
['accept_privacy'],
|
|
18
|
-
['agree_to_terms']
|
|
19
|
-
];
|
|
20
|
-
const advanced = [
|
|
21
|
-
['invite_users', 15],
|
|
22
|
-
['complete_action', 15]
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
beforeAll(async () => {
|
|
26
|
-
({ pg, teardown } = await getConnections());
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterAll(async () => {
|
|
30
|
-
await teardown();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
beforeEach(async () => {
|
|
34
|
-
await pg.beforeEach();
|
|
35
|
-
|
|
36
|
-
for (const name of levels) {
|
|
37
|
-
await pg.any(`INSERT INTO status_public.levels (name) VALUES ($1)`, [name]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
for (const [name, required_count = 1] of newbie) {
|
|
41
|
-
await pg.any(
|
|
42
|
-
`INSERT INTO status_public.level_requirements (name, level, required_count)
|
|
43
|
-
VALUES ($1, $2, $3)`,
|
|
44
|
-
[name, 'newbie', required_count]
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
for (const [name, required_count = 1] of advanced) {
|
|
49
|
-
await pg.any(
|
|
50
|
-
`INSERT INTO status_public.level_requirements (name, level, required_count)
|
|
51
|
-
VALUES ($1, $2, $3)`,
|
|
52
|
-
[name, 'advanced', required_count]
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
afterEach(async () => {
|
|
58
|
-
await pg.afterEach();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('newbie', async () => {
|
|
62
|
-
const steps = [
|
|
63
|
-
'agree_to_terms',
|
|
64
|
-
'accept_cookies',
|
|
65
|
-
'accept_privacy',
|
|
66
|
-
...repeat('complete_action', 3)
|
|
67
|
-
];
|
|
68
|
-
for (const name of steps) {
|
|
69
|
-
await pg.any(
|
|
70
|
-
`INSERT INTO status_public.user_steps (user_id, name) VALUES ($1, $2)`,
|
|
71
|
-
[user_id, name]
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const advancedRequirements = await pg.any(
|
|
76
|
-
`SELECT * FROM status_public.steps_required($1, $2)`,
|
|
77
|
-
['advanced', user_id]
|
|
78
|
-
);
|
|
79
|
-
expect(snapshot({ advancedRequirements })).toMatchSnapshot();
|
|
80
|
-
|
|
81
|
-
const newbieRequirements = await pg.any(
|
|
82
|
-
`SELECT * FROM status_public.steps_required($1, $2)`,
|
|
83
|
-
['newbie', user_id]
|
|
84
|
-
);
|
|
85
|
-
expect(snapshot({ newbieRequirements })).toMatchSnapshot();
|
|
86
|
-
|
|
87
|
-
const [userAchievedNewbie] = await pg.any(
|
|
88
|
-
`SELECT * FROM status_public.user_achieved($1, $2)`,
|
|
89
|
-
['newbie', user_id]
|
|
90
|
-
);
|
|
91
|
-
expect(snapshot({ newbie: userAchievedNewbie })).toMatchSnapshot();
|
|
92
|
-
|
|
93
|
-
const [userAchievedAdvanced] = await pg.any(
|
|
94
|
-
`SELECT * FROM status_public.user_achieved($1, $2)`,
|
|
95
|
-
['advanced', user_id]
|
|
96
|
-
);
|
|
97
|
-
expect(snapshot({ advanced: userAchievedAdvanced })).toMatchSnapshot();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('advanced', async () => {
|
|
101
|
-
const steps = [
|
|
102
|
-
'agree_to_terms',
|
|
103
|
-
'accept_cookies',
|
|
104
|
-
'accept_privacy',
|
|
105
|
-
'upload_profile_image',
|
|
106
|
-
...repeat('invite_users', 3),
|
|
107
|
-
...repeat('complete_action', 21)
|
|
108
|
-
];
|
|
109
|
-
for (const name of steps) {
|
|
110
|
-
await pg.any(
|
|
111
|
-
`INSERT INTO status_public.user_steps (user_id, name) VALUES ($1, $2)`,
|
|
112
|
-
[user_id, name]
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const advancedRequirements = await pg.any(
|
|
117
|
-
`SELECT * FROM status_public.steps_required($1, $2)`,
|
|
118
|
-
['advanced', user_id]
|
|
119
|
-
);
|
|
120
|
-
expect(snapshot({ advancedRequirements })).toMatchSnapshot();
|
|
121
|
-
|
|
122
|
-
const newbieRequirements = await pg.any(
|
|
123
|
-
`SELECT * FROM status_public.steps_required($1, $2)`,
|
|
124
|
-
['newbie', user_id]
|
|
125
|
-
);
|
|
126
|
-
expect(snapshot({ newbieRequirements })).toMatchSnapshot();
|
|
127
|
-
|
|
128
|
-
const [userAchievedNewbie] = await pg.any(
|
|
129
|
-
`SELECT * FROM status_public.user_achieved($1, $2)`,
|
|
130
|
-
['newbie', user_id]
|
|
131
|
-
);
|
|
132
|
-
expect(snapshot({ newbie: userAchievedNewbie })).toMatchSnapshot();
|
|
133
|
-
|
|
134
|
-
const [userAchievedAdvanced] = await pg.any(
|
|
135
|
-
`SELECT * FROM status_public.user_achieved($1, $2)`,
|
|
136
|
-
['advanced', user_id]
|
|
137
|
-
);
|
|
138
|
-
expect(snapshot({ advanced: userAchievedAdvanced })).toMatchSnapshot();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('advanced part II', async () => {
|
|
142
|
-
const partII = [['apply_for_verifier'], ['create_action', 2]];
|
|
143
|
-
|
|
144
|
-
for (const [name, required_count = 1] of partII) {
|
|
145
|
-
await pg.any(
|
|
146
|
-
`INSERT INTO status_public.level_requirements (name, level, required_count)
|
|
147
|
-
VALUES ($1, $2, $3)`,
|
|
148
|
-
[name, 'advanced', required_count]
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const steps = [
|
|
153
|
-
'agree_to_terms',
|
|
154
|
-
'accept_cookies',
|
|
155
|
-
'accept_privacy',
|
|
156
|
-
'upload_profile_image',
|
|
157
|
-
...repeat('invite_users', 3),
|
|
158
|
-
...repeat('complete_action', 10)
|
|
159
|
-
];
|
|
160
|
-
for (const name of steps) {
|
|
161
|
-
await pg.any(
|
|
162
|
-
`INSERT INTO status_public.user_steps (user_id, name) VALUES ($1, $2)`,
|
|
163
|
-
[user_id, name]
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const advancedRequirements = await pg.any(
|
|
168
|
-
`SELECT * FROM status_public.steps_required($1, $2)`,
|
|
169
|
-
['advanced', user_id]
|
|
170
|
-
);
|
|
171
|
-
expect(snapshot({ advancedRequirements })).toMatchSnapshot();
|
|
172
|
-
|
|
173
|
-
const newbieRequirements = await pg.any(
|
|
174
|
-
`SELECT * FROM status_public.steps_required($1, $2)`,
|
|
175
|
-
['newbie', user_id]
|
|
176
|
-
);
|
|
177
|
-
expect(snapshot({ newbieRequirements })).toMatchSnapshot();
|
|
178
|
-
|
|
179
|
-
const [userAchievedNewbie] = await pg.any(
|
|
180
|
-
`SELECT * FROM status_public.user_achieved($1, $2)`,
|
|
181
|
-
['newbie', user_id]
|
|
182
|
-
);
|
|
183
|
-
expect(snapshot({ newbie: userAchievedNewbie })).toMatchSnapshot();
|
|
184
|
-
|
|
185
|
-
const [userAchievedAdvanced] = await pg.any(
|
|
186
|
-
`SELECT * FROM status_public.user_achieved($1, $2)`,
|
|
187
|
-
['advanced', user_id]
|
|
188
|
-
);
|
|
189
|
-
expect(snapshot({ advanced: userAchievedAdvanced })).toMatchSnapshot();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('advanced part III', async () => {
|
|
193
|
-
const partIII = [
|
|
194
|
-
['apply_for_verifier'],
|
|
195
|
-
['approved_for_verifier'],
|
|
196
|
-
['create_action', 2]
|
|
197
|
-
];
|
|
198
|
-
|
|
199
|
-
for (const [name, required_count = 1] of partIII) {
|
|
200
|
-
await pg.any(
|
|
201
|
-
`INSERT INTO status_public.level_requirements (name, level, required_count)
|
|
202
|
-
VALUES ($1, $2, $3)`,
|
|
203
|
-
[name, 'advanced', required_count]
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const steps = [
|
|
208
|
-
'agree_to_terms',
|
|
209
|
-
'accept_cookies',
|
|
210
|
-
'accept_privacy',
|
|
211
|
-
'upload_profile_image',
|
|
212
|
-
...repeat('invite_users', 20),
|
|
213
|
-
...repeat('complete_action', 20),
|
|
214
|
-
...repeat('create_action', 10),
|
|
215
|
-
...repeat('apply_for_verifier', 1),
|
|
216
|
-
...repeat('approved_for_verifier', 1)
|
|
217
|
-
];
|
|
218
|
-
|
|
219
|
-
for (const name of steps) {
|
|
220
|
-
await pg.any(
|
|
221
|
-
`INSERT INTO status_public.user_steps (user_id, name) VALUES ($1, $2)`,
|
|
222
|
-
[user_id, name]
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const advancedRequirements = await pg.any(
|
|
227
|
-
`SELECT * FROM status_public.steps_required($1, $2)`,
|
|
228
|
-
['advanced', user_id]
|
|
229
|
-
);
|
|
230
|
-
expect(snapshot({ advancedRequirements })).toMatchSnapshot();
|
|
231
|
-
|
|
232
|
-
const newbieRequirements = await pg.any(
|
|
233
|
-
`SELECT * FROM status_public.steps_required($1, $2)`,
|
|
234
|
-
['newbie', user_id]
|
|
235
|
-
);
|
|
236
|
-
expect(snapshot({ newbieRequirements })).toMatchSnapshot();
|
|
237
|
-
|
|
238
|
-
const [userAchievedNewbie] = await pg.any(
|
|
239
|
-
`SELECT * FROM status_public.user_achieved($1, $2)`,
|
|
240
|
-
['newbie', user_id]
|
|
241
|
-
);
|
|
242
|
-
expect(snapshot({ newbie: userAchievedNewbie })).toMatchSnapshot();
|
|
243
|
-
|
|
244
|
-
const [userAchievedAdvanced] = await pg.any(
|
|
245
|
-
`SELECT * FROM status_public.user_achieved($1, $2)`,
|
|
246
|
-
['advanced', user_id]
|
|
247
|
-
);
|
|
248
|
-
expect(snapshot({ advanced: userAchievedAdvanced })).toMatchSnapshot();
|
|
249
|
-
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { getConnections, PgTestClient, snapshot } from 'pgsql-test';
|
|
2
|
-
|
|
3
|
-
let pg: PgTestClient;
|
|
4
|
-
let teardown: () => Promise<void>;
|
|
5
|
-
|
|
6
|
-
const user_id = 'b9d22af1-62c7-43a5-b8c4-50630bbd4962';
|
|
7
|
-
|
|
8
|
-
const levels = ['newbie', 'advanced'];
|
|
9
|
-
|
|
10
|
-
const newbie = [
|
|
11
|
-
['upload_profile_image'],
|
|
12
|
-
['complete_action', 5],
|
|
13
|
-
['accept_cookies'],
|
|
14
|
-
['accept_privacy'],
|
|
15
|
-
['agree_to_terms']
|
|
16
|
-
];
|
|
17
|
-
const advanced = [
|
|
18
|
-
['invite_users', 15],
|
|
19
|
-
['complete_action', 15]
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
beforeAll(async () => {
|
|
23
|
-
({ pg, teardown } = await getConnections());
|
|
24
|
-
|
|
25
|
-
await pg.any(`CREATE TABLE status_public.mytable (
|
|
26
|
-
id serial,
|
|
27
|
-
name text,
|
|
28
|
-
toggle text,
|
|
29
|
-
is_approved boolean,
|
|
30
|
-
is_verified boolean default false
|
|
31
|
-
);`);
|
|
32
|
-
|
|
33
|
-
await pg.any(`CREATE TRIGGER mytable_tg1
|
|
34
|
-
BEFORE INSERT ON status_public.mytable
|
|
35
|
-
FOR EACH ROW
|
|
36
|
-
EXECUTE FUNCTION status_private.tg_achievement('name', 'tg_achievement');`);
|
|
37
|
-
|
|
38
|
-
await pg.any(`CREATE TRIGGER mytable_tg2
|
|
39
|
-
BEFORE UPDATE ON status_public.mytable
|
|
40
|
-
FOR EACH ROW
|
|
41
|
-
WHEN (NEW.name IS DISTINCT FROM OLD.name)
|
|
42
|
-
EXECUTE FUNCTION status_private.tg_achievement('name', 'tg_achievement');`);
|
|
43
|
-
|
|
44
|
-
await pg.any(`CREATE TRIGGER mytable_tg3
|
|
45
|
-
BEFORE INSERT ON status_public.mytable
|
|
46
|
-
FOR EACH ROW
|
|
47
|
-
EXECUTE FUNCTION status_private.tg_achievement_toggle('toggle', 'tg_achievement_toggle');`);
|
|
48
|
-
|
|
49
|
-
await pg.any(`CREATE TRIGGER mytable_tg4
|
|
50
|
-
BEFORE UPDATE ON status_public.mytable
|
|
51
|
-
FOR EACH ROW
|
|
52
|
-
WHEN (NEW.toggle IS DISTINCT FROM OLD.toggle)
|
|
53
|
-
EXECUTE FUNCTION status_private.tg_achievement_toggle('toggle', 'tg_achievement_toggle');`);
|
|
54
|
-
|
|
55
|
-
await pg.any(`CREATE TRIGGER mytable_tg5
|
|
56
|
-
BEFORE INSERT ON status_public.mytable
|
|
57
|
-
FOR EACH ROW
|
|
58
|
-
EXECUTE FUNCTION status_private.tg_achievement_boolean('is_approved', 'tg_achievement_boolean');`);
|
|
59
|
-
|
|
60
|
-
await pg.any(`CREATE TRIGGER mytable_tg6
|
|
61
|
-
BEFORE UPDATE ON status_public.mytable
|
|
62
|
-
FOR EACH ROW
|
|
63
|
-
WHEN (NEW.is_approved IS DISTINCT FROM OLD.is_approved)
|
|
64
|
-
EXECUTE FUNCTION status_private.tg_achievement_boolean('is_approved', 'tg_achievement_boolean');`);
|
|
65
|
-
|
|
66
|
-
await pg.any(`CREATE TRIGGER mytable_tg7
|
|
67
|
-
BEFORE INSERT ON status_public.mytable
|
|
68
|
-
FOR EACH ROW
|
|
69
|
-
EXECUTE FUNCTION status_private.tg_achievement_toggle_boolean('is_verified', 'tg_achievement_toggle_boolean');`);
|
|
70
|
-
|
|
71
|
-
await pg.any(`CREATE TRIGGER mytable_tg8
|
|
72
|
-
BEFORE UPDATE ON status_public.mytable
|
|
73
|
-
FOR EACH ROW
|
|
74
|
-
WHEN (NEW.is_verified IS DISTINCT FROM OLD.is_verified)
|
|
75
|
-
EXECUTE FUNCTION status_private.tg_achievement_toggle_boolean('is_verified', 'tg_achievement_toggle_boolean');`);
|
|
76
|
-
|
|
77
|
-
await pg.setContext({
|
|
78
|
-
'jwt.claims.user_id': user_id
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
afterAll(async () => {
|
|
83
|
-
await teardown();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
beforeEach(async () => {
|
|
87
|
-
await pg.beforeEach();
|
|
88
|
-
|
|
89
|
-
for (const name of levels) {
|
|
90
|
-
await pg.any(
|
|
91
|
-
`INSERT INTO status_public.levels (name) VALUES ($1) ON CONFLICT DO NOTHING`,
|
|
92
|
-
[name]
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
for (const [name, required_count = 1] of newbie) {
|
|
97
|
-
await pg.any(
|
|
98
|
-
`INSERT INTO status_public.level_requirements (name, level, required_count)
|
|
99
|
-
VALUES ($1, $2, $3) ON CONFLICT DO NOTHING`,
|
|
100
|
-
[name, 'newbie', required_count]
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
for (const [name, required_count = 1] of advanced) {
|
|
104
|
-
await pg.any(
|
|
105
|
-
`INSERT INTO status_public.level_requirements (name, level, required_count)
|
|
106
|
-
VALUES ($1, $2, $3) ON CONFLICT DO NOTHING`,
|
|
107
|
-
[name, 'advanced', required_count]
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
afterEach(async () => {
|
|
113
|
-
await pg.afterEach();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('newbie', async () => {
|
|
117
|
-
const beforeInsert = await pg.any(
|
|
118
|
-
`SELECT * FROM status_public.user_achievements ORDER BY name`
|
|
119
|
-
);
|
|
120
|
-
expect(snapshot({ beforeInsert })).toMatchSnapshot();
|
|
121
|
-
|
|
122
|
-
await pg.any(
|
|
123
|
-
`INSERT INTO status_public.mytable (name) VALUES ($1)`,
|
|
124
|
-
['upload_profile_image']
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const afterFirstInsert = await pg.any(
|
|
128
|
-
`SELECT * FROM status_public.user_achievements ORDER BY name`
|
|
129
|
-
);
|
|
130
|
-
expect(snapshot({ afterFirstInsert })).toMatchSnapshot();
|
|
131
|
-
|
|
132
|
-
await pg.any(`UPDATE status_public.mytable SET toggle = 'yo'`);
|
|
133
|
-
|
|
134
|
-
const afterUpdateToggleToValue = await pg.any(
|
|
135
|
-
`SELECT * FROM status_public.user_achievements ORDER BY name`
|
|
136
|
-
);
|
|
137
|
-
expect(snapshot({ afterUpdateToggleToValue })).toMatchSnapshot();
|
|
138
|
-
|
|
139
|
-
await pg.any(`UPDATE status_public.mytable SET toggle = NULL`);
|
|
140
|
-
|
|
141
|
-
const afterUpdateToggleToNull = await pg.any(
|
|
142
|
-
`SELECT * FROM status_public.user_achievements ORDER BY name`
|
|
143
|
-
);
|
|
144
|
-
expect(snapshot({ afterUpdateToggleToNull })).toMatchSnapshot();
|
|
145
|
-
|
|
146
|
-
await pg.any(`UPDATE status_public.mytable SET is_verified = TRUE`);
|
|
147
|
-
|
|
148
|
-
const afterIsVerifiedIsTrue = await pg.any(
|
|
149
|
-
`SELECT * FROM status_public.user_achievements ORDER BY name`
|
|
150
|
-
);
|
|
151
|
-
expect(snapshot({ afterIsVerifiedIsTrue })).toMatchSnapshot();
|
|
152
|
-
|
|
153
|
-
await pg.any(`UPDATE status_public.mytable SET is_verified = FALSE`);
|
|
154
|
-
|
|
155
|
-
const afterIsVerifiedIsFalse = await pg.any(
|
|
156
|
-
`SELECT * FROM status_public.user_achievements ORDER BY name`
|
|
157
|
-
);
|
|
158
|
-
expect(snapshot({ afterIsVerifiedIsFalse })).toMatchSnapshot();
|
|
159
|
-
|
|
160
|
-
await pg.any(`UPDATE status_public.mytable SET is_approved = TRUE`);
|
|
161
|
-
|
|
162
|
-
const afterIsApprovedTrue = await pg.any(
|
|
163
|
-
`SELECT * FROM status_public.user_achievements ORDER BY name`
|
|
164
|
-
);
|
|
165
|
-
expect(snapshot({ afterIsApprovedTrue })).toMatchSnapshot();
|
|
166
|
-
});
|
|
File without changes
|