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()
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when promisification is complete
|
|
|
|
it('purchaseProduct() fails when buying invalid product (callback)', done => {
|
2018-06-18 16:50:37 +00:00
|
|
|
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
|
|
|
|
2019-03-13 20:56:01 +00:00
|
|
|
it('purchaseProduct() accepts optional arguments', async () => {
|
|
|
|
const success = await inAppPurchase.purchaseProduct('non-exist')
|
|
|
|
expect(success).to.be.false()
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when promisification is complete
|
|
|
|
it('purchaseProduct() accepts optional arguments (callback)', done => {
|
|
|
|
inAppPurchase.purchaseProduct('non-exist', success => {
|
|
|
|
expect(success).to.be.false()
|
2018-01-10 07:37:05 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2018-04-05 06:33:13 +00:00
|
|
|
|
2019-03-13 20:56:01 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when promisification is complete
|
|
|
|
it('getProducts() returns an empty list when getting invalid product (callback)', done => {
|
2018-06-18 16:50:37 +00:00
|
|
|
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
|
|
|
})
|