Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Wait for endpoint creation to identify user (#13353)
* fix: Wait for endpoint creation to identify user * Update unit test to assert underlying error
- Loading branch information
Showing
10 changed files
with
227 additions
and
33 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
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
73 changes: 73 additions & 0 deletions
73
...s/__tests__/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.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,73 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
getInflightDeviceRegistration, | ||
rejectInflightDeviceRegistration, | ||
resolveInflightDeviceRegistration, | ||
} from '../../../../../src/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration'; | ||
import { InflightDeviceRegistration } from '../../../../../src/pushNotifications/providers/pinpoint/types'; | ||
|
||
describe('inflightDeviceRegistration', () => { | ||
describe('resolveInflightDeviceRegistration', () => { | ||
let getInflightDeviceRegistration: () => InflightDeviceRegistration; | ||
let resolveInflightDeviceRegistration: () => void; | ||
jest.isolateModules(() => { | ||
({ | ||
getInflightDeviceRegistration, | ||
resolveInflightDeviceRegistration, | ||
} = require('../../../../../src/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration')); | ||
}); | ||
|
||
it('creates a pending promise on module load', () => { | ||
expect(getInflightDeviceRegistration()).toBeDefined(); | ||
}); | ||
|
||
it('should resolve the promise', async () => { | ||
const blockedFunction = jest.fn(); | ||
const promise = getInflightDeviceRegistration()?.then(() => { | ||
blockedFunction(); | ||
}); | ||
|
||
expect(blockedFunction).not.toHaveBeenCalled(); | ||
resolveInflightDeviceRegistration(); | ||
await promise; | ||
expect(blockedFunction).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should have released the promise from memory', () => { | ||
expect(getInflightDeviceRegistration()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('rejectInflightDeviceRegistration', () => { | ||
let getInflightDeviceRegistration: () => InflightDeviceRegistration; | ||
let rejectInflightDeviceRegistration: (underlyingError: unknown) => void; | ||
jest.isolateModules(() => { | ||
({ | ||
getInflightDeviceRegistration, | ||
rejectInflightDeviceRegistration, | ||
} = require('../../../../../src/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration')); | ||
}); | ||
|
||
it('creates a pending promise on module load', () => { | ||
expect(getInflightDeviceRegistration()).toBeDefined(); | ||
}); | ||
|
||
it('should reject the promise', async () => { | ||
const underlyingError = new Error('underlying-error'); | ||
const blockedFunction = jest.fn(); | ||
const promise = getInflightDeviceRegistration()?.then(() => { | ||
blockedFunction(); | ||
}); | ||
|
||
expect(blockedFunction).not.toHaveBeenCalled(); | ||
rejectInflightDeviceRegistration(underlyingError); | ||
await expect(promise).rejects.toMatchObject({ | ||
name: 'DeviceRegistrationFailed', | ||
underlyingError, | ||
}); | ||
expect(blockedFunction).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.