@@ -8,23 +8,37 @@ export default function () {
8
8
scopes : "digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search digdir:dialogporten.serviceprovider.admin digdir:dialogporten.correspondence"
9
9
}
10
10
describe ( 'Post run: checking for unpurged dialogs' , ( ) => {
11
- let r = getSO ( 'dialogs/?Search=' + sentinelValue , null , tokenOptions ) ;
12
- expectStatusFor ( r ) . to . equal ( 200 ) ;
13
- expect ( r , 'response' ) . to . have . validJsonBody ( ) ;
14
- var response = r . json ( ) ;
15
- if ( response . items && response . items . length > 0 ) {
16
- console . error ( "Found " + response . items . length + " unpurged dialogs, make sure that all tests clean up after themselves. Purging ..." ) ;
17
- response . items . forEach ( ( item ) => {
18
- console . warn ( "Sentinel purging dialog with id: " + item . id )
19
- let r = purgeSO ( 'dialogs/' + item . id , null , tokenOptions ) ;
11
+ let hasNextPage = false ;
12
+ let continuationToken = "" ;
13
+ let dialogIdsToPurge = [ ] ;
14
+ do {
15
+ let r = getSO ( 'dialogs/?Limit=10&Search=' + sentinelValue + continuationToken , null , tokenOptions ) ;
16
+ expectStatusFor ( r ) . to . equal ( 200 ) ;
17
+ expect ( r , 'response' ) . to . have . validJsonBody ( ) ;
18
+ let response = r . json ( ) ;
19
+ if ( response . items && response . items . length > 0 ) {
20
+ response . items . forEach ( ( item ) => {
21
+ dialogIdsToPurge . push ( item . id ) ;
22
+ } ) ;
23
+
24
+ hasNextPage = response . hasNextPage ;
25
+ continuationToken = "&continuationToken=" + response . continuationToken ;
26
+ }
27
+ } while ( hasNextPage ) ;
28
+
29
+ if ( dialogIdsToPurge . length > 0 ) {
30
+ console . error ( "Found " + dialogIdsToPurge . length + " unpurged dialogs, make sure that all tests clean up after themselves. Purging ..." ) ;
31
+ dialogIdsToPurge . forEach ( ( id ) => {
32
+ console . warn ( "Sentinel purging dialog with id: " + id )
33
+ let r = purgeSO ( 'dialogs/' + id , null , tokenOptions ) ;
20
34
if ( r . status != 204 ) {
21
- console . error ( "Failed to purge dialog with id: " + item . id ) ;
35
+ console . error ( "Failed to purge dialog with id: " + id ) ;
22
36
console . log ( r ) ;
23
37
}
24
38
} ) ;
25
-
26
- // Fail the test after purging for visibility
27
- expect ( response . items . length , 'unpurged dialogs' ) . to . equal ( 0 ) ;
28
39
}
40
+
41
+ // Fail the test after purging for visibility
42
+ expect ( dialogIdsToPurge . length , 'unpurged dialogs' ) . to . equal ( 0 ) ;
29
43
} ) ;
30
44
}
0 commit comments