2018-01-10 06:21:53 +00:00
|
|
|
'use strict'
|
|
|
|
|
2018-06-18 16:50:37 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const dirtyChai = require('dirty-chai')
|
|
|
|
|
|
|
|
const {expect} = chai
|
|
|
|
chai.use(dirtyChai)
|
2018-01-10 06:21:53 +00:00
|
|
|
|
|
|
|
const {remote} = require('electron')
|
|
|
|
|
2018-03-22 13:47:29 +00:00
|
|
|
describe('inAppPurchase module', function () {
|
2018-01-10 06:21:53 +00:00
|
|
|
if (process.platform !== 'darwin') return
|
|
|
|
|
2018-03-22 13:47:29 +00:00
|
|
|
this.timeout(3 * 60 * 1000)
|
|
|
|
|
2018-01-10 09:53:55 +00:00
|
|
|
const {inAppPurchase} = remote
|
|
|
|
|
2018-01-10 06:21:53 +00:00
|
|
|
it('canMakePayments() does not throw', () => {
|
2018-06-18 16:50:37 +00:00
|
|
|
expect(() => {
|
|
|
|
inAppPurchase.canMakePayments()
|
|
|
|
}).to.not.throw()
|
2018-01-10 06:21:53 +00:00
|
|
|
})
|
|
|
|
|
2018-04-05 06:33:13 +00:00
|
|
|
it('finishAllTransactions() does not throw', () => {
|
2018-06-18 16:50:37 +00:00
|
|
|
expect(() => {
|
|
|
|
inAppPurchase.finishAllTransactions()
|
|
|
|
}).to.not.throw()
|
2018-04-05 06:33:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('finishTransactionByDate() does not throw', () => {
|
2018-06-18 16:50:37 +00:00
|
|
|
expect(() => {
|
|
|
|
inAppPurchase.finishTransactionByDate(new Date().toISOString())
|
|
|
|
}).to.not.throw()
|
2018-04-05 06:33:13 +00:00
|
|
|
})
|
|
|
|
|
2018-01-10 06:21:53 +00:00
|
|
|
it('getReceiptURL() returns receipt URL', () => {
|
2018-06-18 16:50:37 +00:00
|
|
|
const correctUrlEnd = inAppPurchase.getReceiptURL().endsWith('_MASReceipt/receipt')
|
|
|
|
expect(correctUrlEnd).to.be.true()
|
2018-01-10 06:21:53 +00:00
|
|
|
})
|
|
|
|
|
2018-06-18 16:50:37 +00:00
|
|
|
it('purchaseProduct() fails when buying invalid product', done => {
|
|
|
|
inAppPurchase.purchaseProduct('non-exist', 1, success => {
|
|
|
|
expect(success).to.be.false()
|
2018-01-10 06:21:53 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2018-01-10 07:37:05 +00:00
|
|
|
|
2018-06-18 16:50:37 +00:00
|
|
|
it('purchaseProduct() accepts optional arguments', done => {
|
2018-01-10 07:37:05 +00:00
|
|
|
inAppPurchase.purchaseProduct('non-exist', () => {
|
|
|
|
inAppPurchase.purchaseProduct('non-exist', 1)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2018-04-05 06:33:13 +00:00
|
|
|
|
2018-06-18 16:50:37 +00:00
|
|
|
it('getProducts() returns an empty list when getting invalid product', done => {
|
|
|
|
inAppPurchase.getProducts(['non-exist'], products => {
|
|
|
|
expect(products).to.be.an('array').of.length(0)
|
2018-04-05 06:33:13 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2018-01-10 06:21:53 +00:00
|
|
|
})
|