1
1
import * as assert from 'assert'
2
- import { StubbedInstance , stubInterface } from 'ts-sinon'
2
+ import sinon , { StubbedInstance , stubInterface } from 'ts-sinon'
3
3
import { CodeWhispererServiceToken } from '../codeWhispererService'
4
4
import { SsoConnectionType } from '../utils'
5
5
import { AWSInitializationOptions , Logging } from '@aws/language-server-runtimes/server-interface'
@@ -46,11 +46,6 @@ describe('ListAllAvailableProfiles Handler', () => {
46
46
$response : { } as any ,
47
47
}
48
48
49
- const listAvailableProfilesResponseWithNextToken = {
50
- ...listAvailableProfilesResponse ,
51
- nextToken : 'some-random-next-token' ,
52
- }
53
-
54
49
beforeEach ( ( ) => {
55
50
logging = stubInterface < Logging > ( )
56
51
codeWhispererService = stubInterface < CodeWhispererServiceToken > ( )
@@ -86,6 +81,12 @@ describe('ListAllAvailableProfiles Handler', () => {
86
81
87
82
describe ( 'Pagination' , ( ) => {
88
83
const MAX_EXPECTED_PAGES = 10
84
+ const SOME_NEXT_TOKEN = 'some-random-next-token'
85
+
86
+ const listAvailableProfilesResponseWithNextToken = {
87
+ ...listAvailableProfilesResponse ,
88
+ nextToken : SOME_NEXT_TOKEN ,
89
+ }
89
90
90
91
it ( 'should paginate if nextToken is defined' , async ( ) => {
91
92
const EXPECTED_CALLS = 3
@@ -104,7 +105,11 @@ describe('ListAllAvailableProfiles Handler', () => {
104
105
endpoints : SOME_AWS_Q_ENDPOINT ,
105
106
} )
106
107
107
- assert . strictEqual ( codeWhispererService . listAvailableProfiles . callCount , EXPECTED_CALLS )
108
+ sinon . assert . calledThrice ( codeWhispererService . listAvailableProfiles )
109
+ assert . strictEqual ( codeWhispererService . listAvailableProfiles . firstCall . args [ 0 ] . nextToken , undefined )
110
+ assert . strictEqual ( codeWhispererService . listAvailableProfiles . secondCall . args [ 0 ] . nextToken , SOME_NEXT_TOKEN )
111
+ assert . strictEqual ( codeWhispererService . listAvailableProfiles . thirdCall . args [ 0 ] . nextToken , SOME_NEXT_TOKEN )
112
+
108
113
assert . deepStrictEqual ( profiles , Array ( EXPECTED_CALLS ) . fill ( EXPECTED_DEVELOPER_PROFILES_LIST [ 0 ] ) )
109
114
} )
110
115
@@ -118,6 +123,13 @@ describe('ListAllAvailableProfiles Handler', () => {
118
123
} )
119
124
120
125
assert . strictEqual ( codeWhispererService . listAvailableProfiles . callCount , MAX_EXPECTED_PAGES )
126
+ codeWhispererService . listAvailableProfiles . getCalls ( ) . forEach ( ( call , index ) => {
127
+ if ( index === 0 ) {
128
+ assert . strictEqual ( call . args [ 0 ] . nextToken , undefined )
129
+ } else {
130
+ assert . strictEqual ( call . args [ 0 ] . nextToken , SOME_NEXT_TOKEN )
131
+ }
132
+ } )
121
133
assert . deepStrictEqual ( profiles , Array ( MAX_EXPECTED_PAGES ) . fill ( EXPECTED_DEVELOPER_PROFILES_LIST [ 0 ] ) )
122
134
} )
123
135
} )
0 commit comments