@@ -24,10 +24,11 @@ import java.time.temporal.ChronoUnit
24
24
25
25
class SubaccountsTest : AbstractTest () {
26
26
private val client = vonage.subaccounts
27
+ private val authType = AuthType .API_KEY_SECRET_HEADER
28
+ private val existingSubaccount = client.subaccount(apiKey2)
27
29
private val baseUrl = " /accounts/$apiKey "
28
30
private val subaccountsUrl = " $baseUrl /subaccounts"
29
31
private val existingSubUrl = " $subaccountsUrl /$apiKey2 "
30
- private val authType = AuthType .API_KEY_SECRET_HEADER
31
32
private val name = " Subaccount department A"
32
33
private val primaryName = " Primary Account"
33
34
private val balance = 93.26
@@ -54,7 +55,7 @@ class SubaccountsTest : AbstractTest() {
54
55
private fun assertEqualsSampleSubaccount (parsed : Account ) {
55
56
assertNotNull(parsed)
56
57
assertEquals(secret, parsed.secret)
57
- assertEquals(apiKey2 , parsed.apiKey)
58
+ assertEquals(existingSubaccount.subaccountKey , parsed.apiKey)
58
59
assertEquals(name, parsed.name)
59
60
assertEquals(apiKey, parsed.primaryAccountApiKey)
60
61
assertEquals(usePrimary, parsed.usePrimaryAccountBalance)
@@ -246,37 +247,39 @@ class SubaccountsTest : AbstractTest() {
246
247
expectedUrl = existingSubUrl, authType = authType,
247
248
expectedResponseParams = sampleSubaccountMap
248
249
)
249
- assertEqualsSampleSubaccount(client.getSubaccount(apiKey2 ))
250
- assert401ApiResponseException<SubaccountsResponseException >(" $subaccountsUrl / $apiKey2 " , HttpMethod .GET ) {
251
- client.getSubaccount(apiKey2 )
250
+ assertEqualsSampleSubaccount(existingSubaccount.get( ))
251
+ assert401ApiResponseException<SubaccountsResponseException >(existingSubUrl , HttpMethod .GET ) {
252
+ existingSubaccount.get( )
252
253
}
253
254
}
254
255
255
256
@Test
256
- fun `update subaccount all parameters ` () {
257
+ fun `update subaccount` () {
257
258
mockPatch(
258
259
expectedUrl = existingSubUrl, authType = authType,
259
260
expectedRequestParams = mapOf (
260
261
" name" to name,
261
- " use_primary_account_balance" to usePrimary,
262
- " suspended" to suspended
262
+ " use_primary_account_balance" to usePrimary
263
263
),
264
264
expectedResponseParams = sampleSubaccountMap
265
265
)
266
- assertEqualsSampleSubaccount(client.updateSubaccount(apiKey2, name, usePrimary, suspended ))
266
+ assertEqualsSampleSubaccount(existingSubaccount.update( name, usePrimary))
267
267
assert401ApiResponseException<SubaccountsResponseException >(existingSubUrl, HttpMethod .PATCH ) {
268
- client.updateSubaccount(apiKey2, suspend = suspended )
268
+ existingSubaccount.update(usePrimaryAccountBalance = usePrimary )
269
269
}
270
270
}
271
271
272
272
@Test
273
- fun `update subaccount name only ` () {
273
+ fun `suspend subaccount` () {
274
274
mockPatch(
275
275
expectedUrl = existingSubUrl, authType = authType,
276
- expectedRequestParams = mapOf (" name " to name ),
276
+ expectedRequestParams = mapOf (" suspended " to suspended ),
277
277
expectedResponseParams = sampleSubaccountMap
278
278
)
279
- assertEqualsSampleSubaccount(client.updateSubaccount(subaccountKey = apiKey2, name = name))
279
+ assertEqualsSampleSubaccount(existingSubaccount.suspended(suspended))
280
+ assert401ApiResponseException<SubaccountsResponseException >(existingSubUrl, HttpMethod .PATCH ) {
281
+ existingSubaccount.suspended(! suspended)
282
+ }
280
283
}
281
284
282
285
@Test
0 commit comments