mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 23:42:12 +00:00
Merge pull request #1 from paglias/iap_fix
chore: show how to use yields
This commit is contained in:
commit
e1fc5355b8
1 changed files with 16 additions and 18 deletions
|
|
@ -1,26 +1,16 @@
|
|||
import { model as User } from '../../../../../website/server/models/user';
|
||||
import requireAgain from 'require-again';
|
||||
import iapLibrary from 'in-app-purchase';
|
||||
import iap from '../../../../../website/server/libs/api-v3/inAppPurchases';
|
||||
|
||||
describe.only('In App Purchases', () => {
|
||||
let user;
|
||||
let pathToIAP = '../../../../../website/server/libs/api-v3/inAppPurchases';
|
||||
let iap;
|
||||
let setupSpy;
|
||||
let validateSpy;
|
||||
let isValidatedSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
user = new User();
|
||||
setupSpy = sinon.spy();
|
||||
validateSpy = sinon.spy();
|
||||
isValidatedSpy = sinon.spy();
|
||||
|
||||
sandbox.stub(iapLibrary, 'setup').returns((err) => setupSpy(err));
|
||||
sandbox.stub(iapLibrary, 'validate').returns((err) => validateSpy(err));
|
||||
sandbox.stub(iapLibrary, 'isValidated').returns(isValidatedSpy);
|
||||
|
||||
iap = requireAgain(pathToIAP);
|
||||
sandbox.stub(iapLibrary, 'setup').yields();
|
||||
sandbox.stub(iapLibrary, 'validate').yields();
|
||||
sandbox.stub(iapLibrary, 'isValidated').yields();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
@ -29,13 +19,21 @@ describe.only('In App Purchases', () => {
|
|||
|
||||
describe('Android', () => {
|
||||
it('applies new valid receipt', async () => {
|
||||
await iap.iapAndroidVerify(user, {
|
||||
let res = await iap.iapAndroidVerify(user, {
|
||||
receipt: {token: 1},
|
||||
});
|
||||
|
||||
expect(setupSpy).to.have.been.called;
|
||||
expect(validateSpy).to.have.been.called;
|
||||
expect(isValidatedSpy).to.have.been.called;
|
||||
console.log(res);
|
||||
});
|
||||
|
||||
it('example with stub yielding an error', async () => {
|
||||
iapLibrary.setup.yields(new Error('an error'));
|
||||
|
||||
let res = await iap.iapAndroidVerify(user, {
|
||||
receipt: {token: 1},
|
||||
});
|
||||
|
||||
console.log(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue