@@ -40,6 +40,7 @@ const {
40
40
removeMemberGroup,
41
41
getGroupRoleByName,
42
42
getGroupRolesForUser,
43
+ skipOnboardingUsersHavingApprovedExtensionRequest,
43
44
} = require ( "../../../models/discordactions" ) ;
44
45
const {
45
46
groupData,
@@ -63,6 +64,8 @@ const { stubbedModelTaskProgressData } = require("../../fixtures/progress/progre
63
64
const { convertDaysToMilliseconds } = require ( "../../../utils/time" ) ;
64
65
const { generateUserStatusData } = require ( "../../fixtures/userStatus/userStatus" ) ;
65
66
const { userState } = require ( "../../../constants/userStatus" ) ;
67
+ const { REQUEST_TYPE , REQUEST_STATE } = require ( "../../../constants/requests" ) ;
68
+ const { createRequest } = require ( "../../../models/requests" ) ;
66
69
67
70
chai . should ( ) ;
68
71
@@ -1064,6 +1067,7 @@ describe("discordactions", function () {
1064
1067
1065
1068
describe ( "updateUsersWith31DaysPlusOnboarding" , function ( ) {
1066
1069
let fetchStub ;
1070
+ let userId0 ;
1067
1071
1068
1072
beforeEach ( async function ( ) {
1069
1073
fetchStub = sinon . stub ( global , "fetch" ) ;
@@ -1087,7 +1091,7 @@ describe("discordactions", function () {
1087
1091
roles : { archived : false , in_discord : true } ,
1088
1092
} ;
1089
1093
1090
- const userId0 = await addUser ( userData [ 0 ] ) ;
1094
+ userId0 = await addUser ( userData [ 0 ] ) ;
1091
1095
const userId1 = await addUser ( userData [ 1 ] ) ;
1092
1096
const userId2 = await addUser ( userData [ 2 ] ) ;
1093
1097
@@ -1133,6 +1137,48 @@ describe("discordactions", function () {
1133
1137
await cleanDb ( ) ;
1134
1138
} ) ;
1135
1139
1140
+ it ( "should add grouponboarding31D when user has an approved extension request but dealine has been passed" , async function ( ) {
1141
+ await createRequest ( {
1142
+ type : REQUEST_TYPE . ONBOARDING ,
1143
+ state : REQUEST_STATE . APPROVED ,
1144
+ newEndsOn : Date . now ( ) - convertDaysToMilliseconds ( 2 ) ,
1145
+ userId : userId0 ,
1146
+ } ) ;
1147
+
1148
+ const res = await updateUsersWith31DaysPlusOnboarding ( ) ;
1149
+ expect ( res . totalOnboardingUsers31DaysCompleted . count ) . to . equal ( 2 ) ;
1150
+ expect ( res . totalOnboarding31dPlusRoleApplied . count ) . to . equal ( 1 ) ;
1151
+ expect ( res . totalOnboarding31dPlusRoleRemoved . count ) . to . equal ( 1 ) ;
1152
+ } ) ;
1153
+
1154
+ it ( "should add grouponboarding31D when user does not have approved extension request" , async function ( ) {
1155
+ await createRequest ( {
1156
+ type : REQUEST_TYPE . ONBOARDING ,
1157
+ state : REQUEST_STATE . PENDING ,
1158
+ newEndsOn : Date . now ( ) + convertDaysToMilliseconds ( 2 ) ,
1159
+ userId : userId0 ,
1160
+ } ) ;
1161
+
1162
+ const res = await updateUsersWith31DaysPlusOnboarding ( ) ;
1163
+ expect ( res . totalOnboardingUsers31DaysCompleted . count ) . to . equal ( 2 ) ;
1164
+ expect ( res . totalOnboarding31dPlusRoleApplied . count ) . to . equal ( 1 ) ;
1165
+ expect ( res . totalOnboarding31dPlusRoleRemoved . count ) . to . equal ( 1 ) ;
1166
+ } ) ;
1167
+
1168
+ it ( "should not add grouponboarding31D when user has approved extension request" , async function ( ) {
1169
+ await createRequest ( {
1170
+ type : REQUEST_TYPE . ONBOARDING ,
1171
+ state : REQUEST_STATE . APPROVED ,
1172
+ newEndsOn : Date . now ( ) + convertDaysToMilliseconds ( 2 ) ,
1173
+ userId : userId0 ,
1174
+ } ) ;
1175
+
1176
+ const res = await updateUsersWith31DaysPlusOnboarding ( ) ;
1177
+ expect ( res . totalOnboardingUsers31DaysCompleted . count ) . to . equal ( 1 ) ;
1178
+ expect ( res . totalOnboarding31dPlusRoleApplied . count ) . to . equal ( 1 ) ;
1179
+ expect ( res . totalOnboarding31dPlusRoleRemoved . count ) . to . equal ( 1 ) ;
1180
+ } ) ;
1181
+
1136
1182
it ( "apply, or remove grouponboarding31D" , async function ( ) {
1137
1183
const res = await updateUsersWith31DaysPlusOnboarding ( ) ;
1138
1184
@@ -1343,4 +1389,33 @@ describe("discordactions", function () {
1343
1389
}
1344
1390
} ) ;
1345
1391
} ) ;
1392
+
1393
+ describe ( "skipOnboardingUsersHavingApprovedExtensionRequest" , function ( ) {
1394
+ const userId0 = "11111" ;
1395
+ const userId1 = "12345" ;
1396
+
1397
+ afterEach ( async function ( ) {
1398
+ sinon . restore ( ) ;
1399
+ await cleanDb ( ) ;
1400
+ } ) ;
1401
+
1402
+ it ( "should return filtered users" , async function ( ) {
1403
+ await createRequest ( {
1404
+ state : REQUEST_STATE . APPROVED ,
1405
+ type : REQUEST_TYPE . ONBOARDING ,
1406
+ newEndsOn : Date . now ( ) + convertDaysToMilliseconds ( 2 ) ,
1407
+ userId : userId0 ,
1408
+ } ) ;
1409
+ const users = await skipOnboardingUsersHavingApprovedExtensionRequest ( [ { id : userId0 } , { id : userId1 } ] ) ;
1410
+ expect ( users . length ) . to . equal ( 1 ) ;
1411
+ expect ( users [ 0 ] . id ) . to . equal ( userId1 ) ;
1412
+ } ) ;
1413
+
1414
+ it ( "should not return filtered users" , async function ( ) {
1415
+ const users = await skipOnboardingUsersHavingApprovedExtensionRequest ( [ { id : userId0 } , { id : userId1 } ] ) ;
1416
+ expect ( users . length ) . to . equal ( 2 ) ;
1417
+ expect ( users [ 0 ] . id ) . to . equal ( userId0 ) ;
1418
+ expect ( users [ 1 ] . id ) . to . equal ( userId1 ) ;
1419
+ } ) ;
1420
+ } ) ;
1346
1421
} ) ;
0 commit comments