diff --git a/src/v2/orders.ts b/src/v2/orders.ts index d3d28c487a4..8d2f7a6781b 100644 --- a/src/v2/orders.ts +++ b/src/v2/orders.ts @@ -39,6 +39,7 @@ export interface OrdersMetaResponse { export interface OrderFeatures { moto: boolean ecom: boolean + paylater: boolean } export interface FeaturesResponse { @@ -49,7 +50,7 @@ export interface FeaturesResponse { msg?: string } -export type KeypairProductType = 'ECOM' | 'MOTO' | 'POS' +export type KeypairProductType = 'ECOM' | 'MOTO' | 'POS' | 'PAYLATER' export interface KeypairsQuery { type?: KeypairProductType diff --git a/test/orders_v2/features.test.ts b/test/orders_v2/features.test.ts index 96bb4c89426..2b757b52ec5 100644 --- a/test/orders_v2/features.test.ts +++ b/test/orders_v2/features.test.ts @@ -47,7 +47,8 @@ describe('v2: orders: can get features', () => { msg: 'Success', results: [{ moto: true, - ecom: false + ecom: false, + paylater: false }] } ] @@ -77,10 +78,10 @@ describe('v2: orders: can get features', () => { const { data, msg } = await ordersV2.features() expect(data).toEqual({ msg: 'Success', - results: [{ moto: true, ecom: false }] + results: [{ moto: true, ecom: false, paylater: false }] }) expect(msg).toBe('Success') - expect(data.results?.[0]).toEqual({ moto: true, ecom: false }) + expect(data.results?.[0]).toEqual({ moto: true, ecom: false, paylater: false }) }) it('rejects on status codes that are not 200', async () => { diff --git a/test/orders_v2/keypairs.test.ts b/test/orders_v2/keypairs.test.ts index a86349d4259..71ada330e2b 100644 --- a/test/orders_v2/keypairs.test.ts +++ b/test/orders_v2/keypairs.test.ts @@ -130,4 +130,59 @@ describe('v2: orders: can get keypairs', () => { name: 'OrderKeypairsFetchFailed' }) }) + + it('can get PAYLATER keypairs', async () => { + const paylaterKeypair = { + ...keypair, + alias: 'PAYLATER key', + productType: 'PAYLATER' + } + + if (process.env.SYSTEM_TEST !== 'true') { + mock.onPost('https://api.tillhub.com/api/v0/users/login').reply(() => { + return [ + 200, + { + token: '', + user: { + id: '123', + legacy_id: legacyId + } + } + ] + }) + + mock.onGet(`https://api.tillhub.com/api/v2/orders/${legacyId}/keypairs?type=PAYLATER`).reply(() => { + return [ + 200, + { + count: 1, + msg: 'Success', + results: [paylaterKeypair] + } + ] + }) + } + + const options = { + credentials: { + username: user.username, + password: user.password + }, + base: process.env.TILLHUB_BASE + } + + const th = new TillhubClient() + + th.init(options) + await th.auth.loginUsername({ + username: user.username, + password: user.password + }) + + const { data, msg, metadata } = await th.ordersV2().keypairs({ type: 'PAYLATER' }) + expect(data).toEqual([paylaterKeypair]) + expect(msg).toBe('Success') + expect(metadata.count).toBe(1) + }) })