-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds test account operation (#960)
* feat: testAccount operation * fix: npm install * fix: dependency issue * fix: lint errors * fix: modified tests & lint errors * fix: test name * fix: updated tests * fix: updated tests
- Loading branch information
1 parent
0f6d378
commit cd0d842
Showing
8 changed files
with
240 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { amazonAdvertising } from './auth' | ||
import { AmazonMarketplaceAdvertisingCountryCode } from '@scaleleap/amazon-marketplaces' | ||
import { CreateAccount } from '../src/operations/test-accounts/types' | ||
|
||
const testAccountOperation = amazonAdvertising.testAccount | ||
const REQUEST_ID = 'VMTZD2V14R745AHA5C4S' | ||
|
||
// Retrieves a single testAccount specified by identifier. | ||
testAccountOperation.getTestAccount(REQUEST_ID) | ||
|
||
// Retrieves one or more testAccounts associated with the authorization passed in the request header. | ||
testAccountOperation.listTestAccounts() | ||
|
||
// Registers a brand in the sandbox environment. | ||
const createTestAccount: CreateAccount = { | ||
countryCode: AmazonMarketplaceAdvertisingCountryCode.IT, | ||
accountType: 'VENDOR', | ||
accountMetaData: { | ||
vendorCode: 'ABCDE', | ||
}, | ||
} | ||
testAccountOperation.createTestAccount(createTestAccount) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Operation } from '../operation' | ||
import { Account, RequestId, CreateAccount, CreateAccountResponse } from './types' | ||
import { Decode, DecodeArray } from '../../decorators' | ||
|
||
export class TestAccountOperation extends Operation { | ||
protected resource = 'testAccounts' | ||
|
||
/** | ||
* Retrieves one or more testAccounts associated with the authorization passed in the request header. | ||
* | ||
* @returns | ||
*/ | ||
@DecodeArray(Account) | ||
public listTestAccounts() { | ||
return this.client.get<Account[]>(`${this.resource}`) | ||
} | ||
|
||
/** | ||
* Retrieves a single account specified by identifier. | ||
* | ||
* @param requestId - | ||
* @returns | ||
*/ | ||
@Decode(Account) | ||
public getTestAccount(requestId: RequestId) { | ||
return this.client.get<Account>(`${this.resource}/?requestId=${requestId}`) | ||
} | ||
|
||
/** | ||
* Create a test account | ||
* @param createAccount | ||
* @returns | ||
*/ | ||
@Decode(CreateAccountResponse) | ||
public createTestAccount(createAccount: CreateAccount) { | ||
return this.client.post<CreateAccountResponse>(`${this.resource}`, { | ||
createAccount, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { isRight } from 'fp-ts/lib/Either' | ||
import * as t from './types' | ||
|
||
describe('CreateAccountResponse', () => { | ||
it('should pass', () => { | ||
const res = t.CreateAccountResponse.decode({ | ||
requestId: 'VMTZD2V14R745AHA5C4S', | ||
}) | ||
|
||
expect(isRight(res)).toBeTruthy() | ||
}) | ||
|
||
it('should fail', () => { | ||
const res = t.CreateAccountResponse.decode({}) | ||
|
||
expect(isRight(res)).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('Account', () => { | ||
it('should pass', () => { | ||
const res = t.Account.decode({ | ||
countryCode: 'IT', | ||
asins: [], | ||
accountType: 'VENDOR', | ||
id: 'ENTITY2TQYXTN0FH5DK', | ||
status: 'COMPLETED', | ||
}) | ||
|
||
expect(isRight(res)).toBeTruthy() | ||
}) | ||
|
||
it('should fail', () => { | ||
const res = t.Account.decode({}) | ||
|
||
expect(isRight(res)).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('CreateAccount', () => { | ||
it('should pass', () => { | ||
const res = t.CreateAccount.decode({ | ||
countryCode: 'IT', | ||
accountMetaData: { | ||
vendorCode: 'ABCDE', | ||
}, | ||
accountType: 'VENDOR', | ||
}) | ||
|
||
expect(isRight(res)).toBeTruthy() | ||
}) | ||
|
||
it('should fail', () => { | ||
const res = t.CreateAccount.decode({}) | ||
|
||
expect(isRight(res)).toBeFalsy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as t from 'io-ts' | ||
import { AmazonMarketplaceAdvertisingCountryCodeType } from '../commons/types' | ||
|
||
export const RequestId = t.string | ||
export type RequestId = t.TypeOf<typeof RequestId> | ||
|
||
export const VendorCode = t.string | ||
export type VendorCode = t.TypeOf<typeof VendorCode> | ||
|
||
export const AccountMetaData = t.type({ | ||
vendorCode: VendorCode, | ||
}) | ||
export type AccountMetaData = t.TypeOf<typeof AccountMetaData> | ||
|
||
export const AccountInfoType = t.union([t.literal('AUTHOR'), t.literal('VENDOR')]) | ||
export type AccountInfoType = t.TypeOf<typeof AccountInfoType> | ||
|
||
export const CreateAccount = t.intersection([ | ||
t.type({ | ||
/** | ||
* The country code identifying the publisher(s) on which ads will run. | ||
*/ | ||
countryCode: AmazonMarketplaceAdvertisingCountryCodeType, | ||
/** | ||
* Account info. | ||
*/ | ||
accountType: AccountInfoType, | ||
}), | ||
t.partial({ | ||
accountMetaData: AccountMetaData, | ||
}), | ||
]) | ||
export type CreateAccount = t.TypeOf<typeof CreateAccount> | ||
|
||
export const CreateAccountResponseStatus = t.union([ | ||
t.literal('IN_PROGRESS'), | ||
t.literal('COMPLETED'), | ||
t.literal('FAILED'), | ||
]) | ||
export type CreateAccountResponseStatus = t.TypeOf<typeof CreateAccountResponseStatus> | ||
|
||
export const CreateAccountResponse = t.type({ | ||
/** | ||
* The RequestId of the account that was created | ||
*/ | ||
requestId: RequestId, | ||
}) | ||
export type CreateAccountResponse = t.TypeOf<typeof CreateAccountResponse> | ||
|
||
export const Account = t.type({ | ||
countryCode: AmazonMarketplaceAdvertisingCountryCodeType, | ||
asins: t.array(t.string), | ||
accountType: AccountInfoType, | ||
id: t.string, | ||
status: CreateAccountResponseStatus, | ||
}) | ||
export type Account = t.TypeOf<typeof Account> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/operations/test-accounts/test-accounts-operation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { OperationProvider } from '../../../src/operations/operation-provider' | ||
import { TestAccountOperation } from '../../../src/operations/test-accounts/test-account-operation' | ||
import { httpClientFactory } from '../../http-client-factory' | ||
import { Account } from '../../../src/operations/test-accounts/types' | ||
import { AmazonMarketplaceAdvertisingCountryCode } from '@scaleleap/amazon-marketplaces' | ||
import { delay } from '../../test-utils' | ||
|
||
jest.setTimeout(15000) | ||
|
||
describe.skip('TestAccountOperation', () => { | ||
const client = httpClientFactory() | ||
const operationProvider = new OperationProvider(client) | ||
const accountOperation = operationProvider.create(TestAccountOperation) | ||
const REQUEST_ID = 'VMTZD2V14R745AHA5C4S' | ||
|
||
describe('listAccounts', () => { | ||
it(`should return an array of accounts`, async () => { | ||
const res: Account[] = await accountOperation.listTestAccounts() | ||
|
||
expect(Array.isArray(res)).toBeTruthy() | ||
}) | ||
}) | ||
|
||
describe('getAccount', () => { | ||
it(`should return a account object`, async () => { | ||
const account = await accountOperation.getTestAccount(REQUEST_ID) | ||
|
||
expect(account).toBeTruthy() | ||
}) | ||
}) | ||
|
||
describe('createTestAccount', () => { | ||
it(`should create the test account`, async () => { | ||
const res = await accountOperation.createTestAccount({ | ||
countryCode: AmazonMarketplaceAdvertisingCountryCode.IT, | ||
accountType: 'VENDOR', | ||
accountMetaData: { | ||
vendorCode: 'ABCDE', | ||
}, | ||
}) | ||
|
||
expect(res).toBeTruthy() | ||
expect(res).toHaveLength(1) | ||
|
||
await delay() | ||
|
||
const account = await accountOperation.getTestAccount(REQUEST_ID) | ||
expect(account).toBeTruthy() | ||
}) | ||
}) | ||
}) |