-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrocer.js
70 lines (60 loc) · 1.44 KB
/
grocer.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* STORE STATUS API
*/
let storeStatus = 'OFFLINE';
/**
* For testing purposes, set the store status
* @param {string} status
*/
export function setStatus(status) {
storeStatus = status;
}
/**
* For testing purposes, reset the store status
*/
export function resetStatus() {
storeStatus = 'OFFLINE';
}
/**
* Invokes the callback with the store's status to simulate an API call
* @param {StatusCallback} callback
*/
export function checkStatus(callback) {
return callback(storeStatus);
}
/**
* INVENTORY API
*/
let lastInventoryQuery = undefined;
let inventoryResponse = undefined;
/**
* For testing purposes, set the response to return when queried
* @param {any} ...nextResponse
*/
export function setResponse(...nextResponse) {
inventoryResponse = nextResponse;
}
/**
* For testing purposes, get the last query
* @return {string}
*/
export function getLastQuery() {
return lastInventoryQuery;
}
/**
* For testing purposes, reset the last query
*/
export function resetQuery() {
lastInventoryQuery = undefined;
inventoryResponse = ['undefined response'];
}
/**
* Checks the inventory (inventoryResponse) then invokes the callback with the result
* @param {GrocerQuery} query
* @param {InventoryCallback} callback
* @return {AvailabilityAction} return the result of the callback
*/
export function checkInventory(query, callback) {
lastInventoryQuery = query;
return callback.apply(null, inventoryResponse);
}