-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmockedTests.js
More file actions
56 lines (51 loc) · 1.75 KB
/
mockedTests.js
File metadata and controls
56 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
console.log("Hello world");
var InAppBilling = require("FuseJS/Billing/Android");
var Observable = require("FuseJS/Observable");
var log = Observable("started\n");
function debugLog(msg) {
console.log("DEBUG: " + msg);
log.value += msg + "\n";
}
var isBusy = Observable(false);
function runTestSteps() {
var testSku = "android.test.purchased";
isBusy.value = true;
try {
InAppBilling.queryProductPurchases().then(function(purchases) {
debugLog("Query product purchases result:\n" + JSON.stringify(purchases));
var testPurchase = purchases.find(function (x) { return x.productId == testSku; });
if (testPurchase) {
debugLog("Starting consume:");
return InAppBilling.consume(testPurchase)
.then(function () { debugLog("purchase consumed!"); });
}
}).then(function() {
debugLog("Querying subscription purchases");
return InAppBilling.querySubscriptionPurchases()
.then(function(purchases) { debugLog("querySubscriptionPurchases result:\n" + JSON.stringify(purchases)); });
}).then(function() {
return InAppBilling.queryProductDetails(testSku)
.then(function(result) { debugLog("queryProductDetails result:\n" + JSON.stringify(result)); });
}).then(function() {
return InAppBilling.purchase(testSku);
}).then(function(purchase) {
debugLog("Purchase successful:\n" + JSON.stringify(purchase));
}).then(function() {
return InAppBilling.purchase("android.test.canceled");
}).catch(function (error) {
log.value += "error: " + error;
}).then(function() {
isBusy.value = false;
});
// log.value = JSON.stringify(JSON.parse(inventory), null, " ");
}
catch (error) {
debugLog("Catched exception:\n" + error);
isBusy.value = false;
}
}
module.exports = {
isBusy: isBusy,
run: runTestSteps,
log: log
};