|
@@ -59,6 +59,48 @@ describe('UserMembershipController', function () {
|
|
|
last_logged_in_at: '2020-05-20T10:41:11.407Z',
|
|
last_logged_in_at: '2020-05-20T10:41:11.407Z',
|
|
|
last_active_at: '2021-05-20T10:41:11.407Z',
|
|
last_active_at: '2021-05-20T10:41:11.407Z',
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: 'mock-member-id-3',
|
|
|
|
|
+ email: 'mock-email-3@foo.com',
|
|
|
|
|
+ last_logged_in_at: '2021-08-10T10:41:11.407Z',
|
|
|
|
|
+ last_active_at: '2021-08-20T10:41:11.407Z',
|
|
|
|
|
+ enrollment: {
|
|
|
|
|
+ managedBy: 'some-other-subscription-id',
|
|
|
|
|
+ enrolledAt: '2021-05-20T10:41:11.407Z',
|
|
|
|
|
+ sso: undefined,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: 'mock-member-id-4',
|
|
|
|
|
+ email: 'mock-email-4@foo.com',
|
|
|
|
|
+ last_logged_in_at: '2021-01-01T10:41:11.407Z',
|
|
|
|
|
+ last_active_at: '2021-01-02T10:41:11.407Z',
|
|
|
|
|
+ enrollment: {
|
|
|
|
|
+ managedBy: 'mock-subscription-id',
|
|
|
|
|
+ enrolledAt: '2021-01-02T10:41:11.407Z',
|
|
|
|
|
+ sso: undefined,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: 'mock-member-id-5',
|
|
|
|
|
+ email: 'mock-email-5@foo.com',
|
|
|
|
|
+ last_logged_in_at: '2023-01-01T10:41:11.407Z',
|
|
|
|
|
+ last_active_at: '2023-01-02T10:41:11.407Z',
|
|
|
|
|
+ enrollment: {
|
|
|
|
|
+ sso: [{ groupId: ctx.subscription._id }],
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: 'mock-member-id-6',
|
|
|
|
|
+ email: 'mock-email-6@foo.com',
|
|
|
|
|
+ last_logged_in_at: '2024-01-01T10:41:11.407Z',
|
|
|
|
|
+ last_active_at: '2024-01-02T10:41:11.407Z',
|
|
|
|
|
+ enrollment: {
|
|
|
|
|
+ managedBy: 'mock-subscription-id',
|
|
|
|
|
+ enrolledAt: '2024-01-02T10:41:11.407Z',
|
|
|
|
|
+ sso: [{ groupId: ctx.subscription._id }],
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
ctx.Settings = {
|
|
ctx.Settings = {
|
|
@@ -143,6 +185,17 @@ describe('UserMembershipController', function () {
|
|
|
SSOConfig: ctx.SSOConfig,
|
|
SSOConfig: ctx.SSOConfig,
|
|
|
}))
|
|
}))
|
|
|
|
|
|
|
|
|
|
+ ctx.Modules = {
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ hooks: {
|
|
|
|
|
+ fire: sinon.stub(),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+ vi.doMock('../../../../app/src/infrastructure/Modules.js', () => ({
|
|
|
|
|
+ default: ctx.Modules,
|
|
|
|
|
+ }))
|
|
|
|
|
+
|
|
|
ctx.UserMembershipController = (await import(modulePath)).default
|
|
ctx.UserMembershipController = (await import(modulePath)).default
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -377,7 +430,7 @@ describe('UserMembershipController', function () {
|
|
|
|
|
|
|
|
it('get users', function (ctx) {
|
|
it('get users', function (ctx) {
|
|
|
sinon.assert.calledWithMatch(
|
|
sinon.assert.calledWithMatch(
|
|
|
- ctx.UserMembershipHandler.getUsers,
|
|
|
|
|
|
|
+ ctx.UserMembershipHandler.promises.getUsers,
|
|
|
ctx.subscription,
|
|
ctx.subscription,
|
|
|
{ modelName: 'Subscription' }
|
|
{ modelName: 'Subscription' }
|
|
|
)
|
|
)
|
|
@@ -398,7 +451,67 @@ describe('UserMembershipController', function () {
|
|
|
it('should export the correct csv', function (ctx) {
|
|
it('should export the correct csv', function (ctx) {
|
|
|
assertCalledWith(
|
|
assertCalledWith(
|
|
|
ctx.res.send,
|
|
ctx.res.send,
|
|
|
- '"email","last_logged_in_at","last_active_at"\n"mock-email-1@foo.com","2020-08-09T12:43:11.467Z","2021-08-09T12:43:11.467Z"\n"mock-email-2@foo.com","2020-05-20T10:41:11.407Z","2021-05-20T10:41:11.407Z"'
|
|
|
|
|
|
|
+ '"email","last_logged_in_at","last_active_at"\n"mock-email-1@foo.com","2020-08-09T12:43:11.467Z","2021-08-09T12:43:11.467Z"\n"mock-email-2@foo.com","2020-05-20T10:41:11.407Z","2021-05-20T10:41:11.407Z"\n"mock-email-3@foo.com","2021-08-10T10:41:11.407Z","2021-08-20T10:41:11.407Z"\n"mock-email-4@foo.com","2021-01-01T10:41:11.407Z","2021-01-02T10:41:11.407Z"\n"mock-email-5@foo.com","2023-01-01T10:41:11.407Z","2023-01-02T10:41:11.407Z"\n"mock-email-6@foo.com","2024-01-01T10:41:11.407Z","2024-01-02T10:41:11.407Z"'
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('exportCsv when group is managed', function () {
|
|
|
|
|
+ beforeEach(function (ctx) {
|
|
|
|
|
+ ctx.req.entity = Object.assign(
|
|
|
|
|
+ { managedUsersEnabled: true },
|
|
|
|
|
+ ctx.subscription
|
|
|
|
|
+ )
|
|
|
|
|
+ ctx.req.entityConfig = EntityConfigs.groupManagers
|
|
|
|
|
+ ctx.res = new MockResponse()
|
|
|
|
|
+ ctx.UserMembershipController.exportCsv(ctx.req, ctx.res)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should export the correct csv', function (ctx) {
|
|
|
|
|
+ assertCalledWith(
|
|
|
|
|
+ ctx.res.send,
|
|
|
|
|
+ '"email","last_logged_in_at","last_active_at","managed"\n"mock-email-1@foo.com","2020-08-09T12:43:11.467Z","2021-08-09T12:43:11.467Z",false\n"mock-email-2@foo.com","2020-05-20T10:41:11.407Z","2021-05-20T10:41:11.407Z",false\n"mock-email-3@foo.com","2021-08-10T10:41:11.407Z","2021-08-20T10:41:11.407Z",false\n"mock-email-4@foo.com","2021-01-01T10:41:11.407Z","2021-01-02T10:41:11.407Z",true\n"mock-email-5@foo.com","2023-01-01T10:41:11.407Z","2023-01-02T10:41:11.407Z",false\n"mock-email-6@foo.com","2024-01-01T10:41:11.407Z","2024-01-02T10:41:11.407Z",true'
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('exportCsv when group has SSO', function () {
|
|
|
|
|
+ beforeEach(function (ctx) {
|
|
|
|
|
+ ctx.req.entity = Object.assign(
|
|
|
|
|
+ { ssoConfig: 'sso-config-id' },
|
|
|
|
|
+ ctx.subscription
|
|
|
|
|
+ )
|
|
|
|
|
+ ctx.req.entityConfig = EntityConfigs.groupManagers
|
|
|
|
|
+ ctx.Modules.promises.hooks.fire.resolves([true])
|
|
|
|
|
+ ctx.res = new MockResponse()
|
|
|
|
|
+ ctx.UserMembershipController.exportCsv(ctx.req, ctx.res)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should export the correct csv', function (ctx) {
|
|
|
|
|
+ assertCalledWith(
|
|
|
|
|
+ ctx.res.send,
|
|
|
|
|
+ '"email","last_logged_in_at","last_active_at","sso"\n"mock-email-1@foo.com","2020-08-09T12:43:11.467Z","2021-08-09T12:43:11.467Z",false\n"mock-email-2@foo.com","2020-05-20T10:41:11.407Z","2021-05-20T10:41:11.407Z",false\n"mock-email-3@foo.com","2021-08-10T10:41:11.407Z","2021-08-20T10:41:11.407Z",false\n"mock-email-4@foo.com","2021-01-01T10:41:11.407Z","2021-01-02T10:41:11.407Z",false\n"mock-email-5@foo.com","2023-01-01T10:41:11.407Z","2023-01-02T10:41:11.407Z",true\n"mock-email-6@foo.com","2024-01-01T10:41:11.407Z","2024-01-02T10:41:11.407Z",true'
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('exportCsv when group has SSO and managed users enabled', function () {
|
|
|
|
|
+ beforeEach(function (ctx) {
|
|
|
|
|
+ ctx.req.entity = Object.assign(
|
|
|
|
|
+ { managedUsersEnabled: true },
|
|
|
|
|
+ { ssoConfig: 'sso-config-id' },
|
|
|
|
|
+ ctx.subscription
|
|
|
|
|
+ )
|
|
|
|
|
+ ctx.req.entityConfig = EntityConfigs.groupManagers
|
|
|
|
|
+ ctx.Modules.promises.hooks.fire.resolves([true])
|
|
|
|
|
+ ctx.res = new MockResponse()
|
|
|
|
|
+ ctx.UserMembershipController.exportCsv(ctx.req, ctx.res)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should export the correct csv', function (ctx) {
|
|
|
|
|
+ assertCalledWith(
|
|
|
|
|
+ ctx.res.send,
|
|
|
|
|
+ '"email","last_logged_in_at","last_active_at","managed","sso"\n"mock-email-1@foo.com","2020-08-09T12:43:11.467Z","2021-08-09T12:43:11.467Z",false,false\n"mock-email-2@foo.com","2020-05-20T10:41:11.407Z","2021-05-20T10:41:11.407Z",false,false\n"mock-email-3@foo.com","2021-08-10T10:41:11.407Z","2021-08-20T10:41:11.407Z",false,false\n"mock-email-4@foo.com","2021-01-01T10:41:11.407Z","2021-01-02T10:41:11.407Z",true,false\n"mock-email-5@foo.com","2023-01-01T10:41:11.407Z","2023-01-02T10:41:11.407Z",false,true\n"mock-email-6@foo.com","2024-01-01T10:41:11.407Z","2024-01-02T10:41:11.407Z",true,true'
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|