-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(auth): WIP - add tests for Apple IAP modules
* add AppleIAP module test (currently has import error)
- Loading branch information
1 parent
bb52af3
commit 7bca437
Showing
3 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/fxa-auth-server/lib/payments/iap/apple-app-store/index.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,5 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
export { AppleIAP } from './apple-iap'; |
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
147 changes: 147 additions & 0 deletions
147
packages/fxa-auth-server/test/local/payments/iap/apple-app-store/apple-iap.js
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,147 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'use strict'; | ||
|
||
const sinon = require('sinon'); | ||
const { assert } = require('chai'); | ||
const { default: Container } = require('typedi'); | ||
|
||
const { mockLog } = require('../../../../mocks'); | ||
const { | ||
AuthFirestore, | ||
AuthLogger, | ||
AppConfig, | ||
} = require('../../../../../lib/types'); | ||
const { AppleIAP } = require('../../../../../lib/payments/iap/apple-app-store'); | ||
|
||
const mockConfig = { | ||
authFirestore: { | ||
prefix: 'mock-fxa-', | ||
}, | ||
subscriptions: { | ||
appStore: { | ||
credentials: { | ||
org_mozilla_ios_FirefoxVPN: { | ||
issuerId: 'issuer_id', | ||
serverApiKey: 'key', | ||
serverApiKeyId: 'key_id', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('AppleIAP', () => { | ||
let sandbox; | ||
let firestore; | ||
let log; | ||
let appleIAP; | ||
let planDbRefMock; | ||
let purchasesDbRefMock; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
planDbRefMock = {}; | ||
purchasesDbRefMock = {}; | ||
const collectionMock = sinon.stub(); | ||
collectionMock.onFirstCall().returns(planDbRefMock); | ||
collectionMock.onSecondCall().returns(purchasesDbRefMock); | ||
firestore = { | ||
collection: collectionMock, | ||
}; | ||
log = mockLog(); | ||
Container.set(AuthFirestore, firestore); | ||
Container.set(AuthLogger, log); | ||
Container.set(AppConfig, mockConfig); | ||
Container.remove(AppleIAP); | ||
}); | ||
|
||
afterEach(() => { | ||
Container.reset(); | ||
sandbox.restore(); | ||
}); | ||
|
||
it('can be instantiated', () => { | ||
const appleIAP = Container.get(AppleIAP); | ||
assert.strictEqual(appleIAP.log, log); | ||
assert.strictEqual(appleIAP.firestore, firestore); | ||
assert.strictEqual(appleIAP.prefix, 'mock-fxa-iap-'); | ||
}); | ||
|
||
describe('plans', () => { | ||
beforeEach(() => { | ||
// Create and set a new one per test | ||
appleIAP = new AppleIAP(); | ||
Container.set(AppleIAP, appleIAP); | ||
}); | ||
|
||
it('returns successfully', async () => { | ||
planDbRefMock.doc = sinon.fake.returns({ | ||
get: sinon.fake.resolves({ | ||
exists: true, | ||
data: sinon.fake.returns({ plans: 'testObject' }), | ||
}), | ||
}); | ||
const result = await appleIAP.plans(); | ||
assert.strictEqual(result, 'testObject'); | ||
}); | ||
|
||
it('throws error with no document found', async () => { | ||
planDbRefMock.doc = sinon.fake.returns({ | ||
get: sinon.fake.resolves({ | ||
exists: false, | ||
}), | ||
}); | ||
try { | ||
await appleIAP.plans('testApp'); | ||
assert.fail('Expected exception thrown.'); | ||
} catch (err) { | ||
assert.strictEqual( | ||
err.message, | ||
'IAP Plans document does not exist for testApp' | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
describe('getBundleId', () => { | ||
beforeEach(() => { | ||
// Create and set a new one per test | ||
appleIAP = new AppleIAP(); | ||
Container.set(AppleIAP, appleIAP); | ||
}); | ||
|
||
it('returns successfully', async () => { | ||
planDbRefMock.doc = sinon.fake.returns({ | ||
get: sinon.fake.resolves({ | ||
exists: true, | ||
data: sinon.fake.returns({ | ||
packageName: 'org.mozilla.testApp', | ||
plans: 'testObject', | ||
}), | ||
}), | ||
}); | ||
const result = await appleIAP.getBundleId('testApp'); | ||
assert.strictEqual(result, 'org.mozilla.testApp'); | ||
}); | ||
|
||
it('throws error with no document found', async () => { | ||
planDbRefMock.doc = sinon.fake.returns({ | ||
get: sinon.fake.resolves({ | ||
exists: false, | ||
}), | ||
}); | ||
try { | ||
await appleIAP.packageName('testApp'); | ||
assert.fail('Expected exception thrown.'); | ||
} catch (err) { | ||
assert.strictEqual( | ||
err.message, | ||
'IAP Plans document does not exist for testApp' | ||
); | ||
} | ||
}); | ||
}); | ||
}); |