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')
|
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { expect } = chai
|
2018-06-18 16:50:37 +00:00
|
|
|
chai.use(dirtyChai)
|
2018-01-10 06:21:53 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { remote } = require('electron')
|
2018-01-10 06:21:53 +00:00
|
|
|
|
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-09-13 16:10:51 +00:00
|
|
|
const { inAppPurchase } = remote
|
2018-01-10 09:53:55 +00:00
|
|
|
|
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
|
|
|
})
|
|
|
|
|
2019-03-13 20:56:01 +00:00
|
|
|
it('purchaseProduct() fails when buying invalid product', async () => {
|
|
|
|
const success = await inAppPurchase.purchaseProduct('non-exist', 1)
|
|
|
|
expect(success).to.be.false()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('purchaseProduct() accepts optional arguments', async () => {
|
|
|
|
const success = await inAppPurchase.purchaseProduct('non-exist')
|
|
|
|
expect(success).to.be.false()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('getProducts() returns an empty list when getting invalid product', async () => {
|
|
|
|
const products = await inAppPurchase.getProducts(['non-exist'])
|
|
|
|
expect(products).to.be.an('array').of.length(0)
|
|
|
|
})
|
2018-01-10 06:21:53 +00:00
|
|
|
})
|