Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions models/NotificationHistoryResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2023 Apple Inc. Licensed under MIT License.

import { NotificationHistoryResponseItem } from "./NotificationHistoryResponseItem";
import { NotificationHistoryResponseItem, NotificationHistoryResponseItemValidator } from "./NotificationHistoryResponseItem";
import { Validator } from "./Validator";

/**
Expand Down Expand Up @@ -34,7 +34,7 @@ export interface NotificationHistoryResponse {


export class NotificationHistoryResponseValidator implements Validator<NotificationHistoryResponse> {
static readonly notificationHistoryResponseItemValidator = new NotificationHistoryResponseValidator()
static readonly notificationHistoryResponseItemValidator = new NotificationHistoryResponseItemValidator()
validate(obj: any): obj is NotificationHistoryResponse {
if ((typeof obj['paginationToken'] !== 'undefined') && !(typeof obj['paginationToken'] === "string" || obj['paginationToken'] instanceof String)) {
return false
Expand Down
41 changes: 40 additions & 1 deletion tests/unit-tests/api_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,45 @@ describe('The api client ', () => {
expect(expectedNotificationHistory).toStrictEqual(notificationHistoryResponse.notificationHistory)
})

it.each([
{ field: 'signedPayload', item: { signedPayload: 123 } },
{ field: 'sendAttempts', item: { sendAttempts: 'not-an-array' } },
{ field: 'attemptDate', item: { sendAttempts: [{ attemptDate: 'not-a-number' }] } },
{ field: 'sendAttemptResult', item: { sendAttempts: [{ sendAttemptResult: 123 }] } },
{
field: 'later send attempt',
item: { sendAttempts: [{ sendAttemptResult: 'SUCCESS' }, { attemptDate: 'not-a-number' }] }
}
])('rejects notification history with invalid $field', async ({ item }) => {
const body = { notificationHistory: [{ signedPayload: 'valid_payload' }, item] }
const client = getAppStoreServerAPIClient(JSON.stringify(body), 200, () => {})

await expect(client.getNotificationHistory(null, {})).rejects.toThrow('Unexpected response body format')
})

it.each([
{ description: 'omitted history', body: {} },
{ description: 'empty history', body: { notificationHistory: [] } },
{ description: 'omitted item fields', body: { notificationHistory: [{}] } },
{
description: 'omitted send attempts',
body: { notificationHistory: [{ signedPayload: 'signed_payload' }] }
},
{ description: 'empty send attempts', body: { notificationHistory: [{ sendAttempts: [] }] } },
{
description: 'omitted send attempt fields',
body: { notificationHistory: [{ sendAttempts: [{}] }] }
},
{
description: 'an unknown send attempt result',
body: { notificationHistory: [{ sendAttempts: [{ sendAttemptResult: 'FUTURE_RESULT' }] }] }
}
])('accepts notification history with $description', async ({ body }) => {
const client = getAppStoreServerAPIClient(JSON.stringify(body), 200, () => {})

await expect(client.getNotificationHistory(null, {})).resolves.toStrictEqual(body)
})

it('calls getTransactionHistory V1', async () => {
const client = getClientWithBody("tests/resources/models/transactionHistoryResponse.json", (path: string, parsedQueryParameters: URLSearchParams, method: string, requestBody: string | Buffer | undefined, headers: { [key: string]: string; }) => {
expect("GET").toBe(method)
Expand Down Expand Up @@ -1144,4 +1183,4 @@ describe('The api client ', () => {

await client.finishTransaction("1234");
})
})
})