|
| 1 | +import { CoreModuleDirector } from "../../../src/core/CoreModuleDirector"; |
| 2 | +import { OSModel } from "../../../src/core/modelRepo/OSModel"; |
| 3 | +import { SupportedSubscription } from "../../../src/core/models/SubscriptionModels"; |
| 4 | +import { TestEnvironment } from "../../support/environment/TestEnvironment"; |
| 5 | +import { getCoreModuleDirector, getDummyPushSubscriptionOSModel } from "../../support/helpers/core"; |
| 6 | + |
| 7 | +describe('CoreModuleDirector tests', () => { |
| 8 | + beforeEach(() => { |
| 9 | + TestEnvironment.initialize(); |
| 10 | + }); |
| 11 | + describe('getPushSubscriptionModel', () => { |
| 12 | + beforeEach(() => { |
| 13 | + jest.resetAllMocks(); |
| 14 | + }); |
| 15 | + |
| 16 | + async function getPushSubscriptionModel(): Promise<OSModel<SupportedSubscription> | undefined> { |
| 17 | + return (await getCoreModuleDirector()).getPushSubscriptionModel(); |
| 18 | + } |
| 19 | + |
| 20 | + test('returns undefined when it find no push records', async () => { |
| 21 | + expect(await getPushSubscriptionModel()).toBe(undefined); |
| 22 | + }); |
| 23 | + |
| 24 | + test('returns current subscription when available', async () => { |
| 25 | + const pushModelCurrent = getDummyPushSubscriptionOSModel(); |
| 26 | + test.stub(CoreModuleDirector.prototype, "getPushSubscriptionModelByCurrentToken", Promise.resolve(pushModelCurrent)); |
| 27 | + expect(await getPushSubscriptionModel()).toBe(pushModelCurrent); |
| 28 | + }); |
| 29 | + |
| 30 | + test('returns last known subscription when current is unavailable', async () => { |
| 31 | + const pushModelLastKnown = getDummyPushSubscriptionOSModel(); |
| 32 | + test.stub(CoreModuleDirector.prototype, "getPushSubscriptionModelByLastKnownToken", Promise.resolve(pushModelLastKnown)); |
| 33 | + expect(await getPushSubscriptionModel()).toBe(pushModelLastKnown); |
| 34 | + }); |
| 35 | + |
| 36 | + test('returns current subscription over last known', async () => { |
| 37 | + const pushModelCurrent = getDummyPushSubscriptionOSModel(); |
| 38 | + test.stub(CoreModuleDirector.prototype, "getPushSubscriptionModelByCurrentToken", Promise.resolve(pushModelCurrent)); |
| 39 | + |
| 40 | + const pushModelLastKnown = getDummyPushSubscriptionOSModel(); |
| 41 | + test.stub(CoreModuleDirector.prototype, "getPushSubscriptionModelByLastKnownToken", Promise.resolve(pushModelLastKnown)); |
| 42 | + |
| 43 | + expect(await getPushSubscriptionModel()).toBe(pushModelCurrent); |
| 44 | + }); |
| 45 | + }); |
| 46 | +}); |
0 commit comments