@@ -2,14 +2,14 @@ import o from "@tutao/otest"
2
2
import { loadUserExportData } from "../../../src/common/settings/UserDataExporter.js"
3
3
import { EntityClient } from "../../../src/common/api/common/EntityClient.js"
4
4
import { LoginController } from "../../../src/common/api/main/LoginController.js"
5
- import { FileController } from "../../../src/common/file/FileController.js"
6
- import { object , when } from "testdouble"
5
+ import { matchers , object , when } from "testdouble"
7
6
import { CustomerTypeRef , Group , GroupInfo , GroupInfoTypeRef , GroupTypeRef , User } from "../../../src/common/api/entities/sys/TypeRefs.js"
8
7
import { formatDateTimeUTC } from "../../../src/calendar-app/calendar/export/CalendarExporter.js"
9
8
import { CounterFacade } from "../../../src/common/api/worker/facades/lazy/CounterFacade.js"
10
9
import { CounterType } from "../../../src/common/api/common/TutanotaConstants.js"
11
10
import { CounterValueTypeRef } from "../../../src/common/api/entities/monitor/TypeRefs.js"
12
11
import { createTestEntity } from "../TestUtils.js"
12
+ import { TypeRef } from "@tutao/tutanota-utils"
13
13
14
14
o . spec ( "user data export" , function ( ) {
15
15
const customerId = "customerId"
@@ -19,34 +19,42 @@ o.spec("user data export", function () {
19
19
customer : customerId ,
20
20
} as User
21
21
22
- let allUserGroupInfos : Array < GroupInfo >
22
+ let allUserGroupInfos : GroupInfo [ ]
23
23
24
24
let entityClientMock : EntityClient
25
25
let counterFacadeMock : CounterFacade
26
26
let loginsMock : LoginController
27
- let fileControllerMock : FileController
27
+ let allGroups : Group [ ]
28
28
29
29
o . beforeEach ( function ( ) {
30
30
allUserGroupInfos = [ ]
31
31
32
32
loginsMock = object ( )
33
33
when ( loginsMock . getUserController ( ) ) . thenReturn ( {
34
- user,
34
+ loadCustomer : ( ) =>
35
+ Promise . resolve (
36
+ createTestEntity ( CustomerTypeRef , {
37
+ userGroups : userGroupsId ,
38
+ _id : customerId ,
39
+ } ) ,
40
+ ) ,
35
41
// we only test the case where we are global admin for now
36
42
isGlobalAdmin : ( ) => true ,
37
43
} )
38
44
39
45
entityClientMock = object ( )
40
- when ( entityClientMock . load ( CustomerTypeRef , customerId ) ) . thenResolve ( {
41
- userGroups : userGroupsId ,
42
- } )
43
46
when ( entityClientMock . loadAll ( GroupInfoTypeRef , userGroupsId ) ) . thenResolve ( allUserGroupInfos )
47
+ when ( entityClientMock . loadMultiple ( GroupTypeRef , null , matchers . anything ( ) ) ) . thenDo (
48
+ ( _typeref : TypeRef < Group > , _list : Id | null , groups : readonly Id [ ] ) => {
49
+ return Promise . resolve ( allGroups . filter ( ( g ) => groups . includes ( g . _id ) ) )
50
+ } ,
51
+ )
44
52
45
53
counterFacadeMock = object ( )
46
- fileControllerMock = object ( )
54
+ allGroups = [ ]
47
55
} )
48
56
49
- o ( "should load and return correct user data " , async function ( ) {
57
+ o . test ( "should load and return correct user data " , async function ( ) {
50
58
const oneCreated = new Date ( 1655294400000 ) // 2022-06-15 12:00:00 GMT+0
51
59
const oneDeleted = new Date ( 1655469000000 ) // "2022-06-17 12:30:00 GMT +0"
52
60
const twoCreated = new Date ( 1657886400000 ) // "2022-07-15 12:00:00 GMT+0"
@@ -59,38 +67,60 @@ o.spec("user data export", function () {
59
67
// missing counter for second user!
60
68
] )
61
69
62
- const [ first , second ] = await loadUserExportData ( entityClientMock , loginsMock , counterFacadeMock )
70
+ let onProgressLastComplete : number | undefined
71
+ let onProgressLastTotal : number | undefined
72
+ let onProgressCalledTimes = 0
73
+
74
+ const [ first , second ] = await loadUserExportData ( entityClientMock , loginsMock , counterFacadeMock , ( complete , total ) => {
75
+ if ( onProgressLastComplete != null ) {
76
+ o . check ( complete > onProgressLastComplete ) . equals ( true )
77
+ } else {
78
+ o . check ( complete ) . equals ( 0 )
79
+ }
80
+ if ( onProgressLastTotal != null ) {
81
+ o . check ( total ) . equals ( onProgressLastTotal )
82
+ }
83
+ onProgressLastComplete = complete
84
+ onProgressLastTotal = total
85
+ onProgressCalledTimes += 1
86
+ } )
87
+
88
+ o . check ( first . name ) . equals ( "my name" )
89
+ o . check ( second . name ) . equals ( "eman ym" )
63
90
64
- o ( first . name ) . equals ( "my name " )
65
- o ( second . name ) . equals ( "eman ym " )
91
+ o . check ( first . mailAddress ) . equals ( "[email protected] " )
92
+ o . check ( second . mailAddress ) . equals ( "[email protected] " )
66
93
67
- o ( first . mailAddress ) . equals ( "[email protected] " )
68
- o ( second . mailAddress ) . equals ( "[email protected] " )
94
+ o . check ( formatDateTimeUTC ( first . created ) ) . equals ( "20220615T120000Z " )
95
+ o . check ( formatDateTimeUTC ( second . created ) ) . equals ( "20220715T120000Z " )
69
96
70
- o ( formatDateTimeUTC ( first . created ) ) . equals ( "20220615T120000Z " )
71
- o ( formatDateTimeUTC ( second . created ) ) . equals ( "20220715T120000Z" )
97
+ o . check ( formatDateTimeUTC ( first . deleted ! ) ) . equals ( "20220617T123000Z " )
98
+ o . check ( second . deleted ) . equals ( null )
72
99
73
- o ( formatDateTimeUTC ( first . deleted ! ) ) . equals ( "20220617T123000Z" )
74
- o ( second . deleted ) . equals ( null )
100
+ o . check ( first . usedStorage ) . equals ( 100 )
101
+ o . check ( second . usedStorage ) . equals ( 0 )
75
102
76
- o ( first . usedStorage ) . equals ( 100 )
77
- o ( second . usedStorage ) . equals ( 0 )
103
+ o . check ( first . aliases ) . deepEquals ( [ "[email protected] " , "[email protected] " ] )
104
+ o . check ( second . aliases ) . deepEquals ( [ ] )
78
105
79
- o ( first . aliases ) . deepEquals ( [ "[email protected] " , "[email protected] " ] )
80
- o ( second . aliases ) . deepEquals ( [ ] )
106
+ o . check ( onProgressLastComplete ) . equals ( 2 )
107
+ o . check ( onProgressLastTotal ) . equals ( 2 )
108
+ o . check ( onProgressCalledTimes ) . equals ( 2 )
81
109
} )
82
110
83
111
function addUser ( name , mailAddress , created , deleted , usedStorage , aliases , userId , groupId , storageCounterId ) {
84
- allUserGroupInfos . push ( {
85
- name,
86
- mailAddress,
87
- created,
88
- deleted,
89
- mailAddressAliases : aliases . map ( ( alias ) => ( { mailAddress : alias } ) ) ,
90
- group : groupId ,
91
- } as GroupInfo )
92
-
93
- const group = { storageCounter : storageCounterId } as Group
94
- when ( entityClientMock . load ( GroupTypeRef , groupId ) ) . thenResolve ( { storageCounter : group . storageCounter } )
112
+ allUserGroupInfos . push (
113
+ createTestEntity ( GroupInfoTypeRef , {
114
+ name,
115
+ mailAddress,
116
+ created,
117
+ deleted,
118
+ mailAddressAliases : aliases . map ( ( alias ) => ( { mailAddress : alias } ) ) ,
119
+ group : groupId ,
120
+ } ) ,
121
+ )
122
+
123
+ const group = createTestEntity ( GroupTypeRef , { storageCounter : storageCounterId , _id : groupId } )
124
+ allGroups . push ( group )
95
125
}
96
126
} )
0 commit comments