Skip to content

Commit

Permalink
Adds mock implementations for API calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
womcauliff committed Jul 15, 2019
1 parent 37f927a commit 09baace
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/useAppHook.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useReducer, useEffect } from 'react';
import { $, in$ } from 'moneysafe';
import { getItems, postInvoice } from './utils';
// import { getItems, postInvoice } from './utils';
import { getItems, postInvoice } from './utils/__mocks__';

/**
* Determines if a given value is a valid quantity
Expand Down Expand Up @@ -147,7 +148,6 @@ export default function useAppHook(SALESTAX) {
const fetchLineItems = async () => {
try {
const response = await getItems();
console.log(response, response.data);
dispatch({
type: 'POPULATE_LINE_ITEMS',
lineItemsAPI: response.data.data,
Expand Down Expand Up @@ -184,13 +184,7 @@ export default function useAppHook(SALESTAX) {

const submitInvoice = async () => {
try {
const response = await postInvoice(
selectedLineItems,
tax,
subTotal,
grandTotal
);
console.log(response, response.data);
await postInvoice(selectedLineItems, tax, subTotal, grandTotal);
dispatch({ type: 'POST_SUCCEEDED' });
} catch (error) {
console.log(error);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/__mocks__/getItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import mockData from './mockData';

function getItems() {
return new Promise(resolve => setTimeout(() => resolve(mockData), 1500));
}

export default getItems;
2 changes: 2 additions & 0 deletions src/utils/__mocks__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as getItems } from './getItems';
export { default as postInvoice } from './postInvoice';
291 changes: 291 additions & 0 deletions src/utils/__mocks__/mockData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
{
"data": {
"current_page": 1,
"data": [
{
"id": "412fa6b9-de0c-49e8-b023-f66a878e2b8d",
"user_id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"merchant_id": "6d329797-b64d-47d1-a457-4798e2b361b5",
"thumbnail_id": null,
"item": "Item 2",
"code": "item-2",
"category": "default",
"details": "details about Item 2",
"is_active": true,
"is_taxable": true,
"is_service": false,
"is_subscription": false,
"is_discount": false,
"price": 5,
"in_stock": 100,
"low_stock_alert": 10,
"meta": [],
"created_at": "2019-04-16 15:29:49",
"updated_at": "2019-04-23 13:03:28",
"deleted_at": null,
"user": {
"id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"system_admin": false,
"name": "user",
"email": "[email protected]",
"email_verification_sent_at": "2019-04-16 15:29:48",
"email_verified_at": "2019-04-16 15:29:48",
"is_api_key": false,
"acknowledgments": {
"tutorial": true
},
"created_at": "2019-04-16 15:29:48",
"updated_at": "2019-04-16 15:29:48",
"deleted_at": null,
"brand": null,
"gravatar": "//www.gravatar.com/avatar/edca79f00b23dfdc0f0eb803630be006",
"team_admin": null,
"team_enabled": null,
"team_role": null,
"merchant_options": [],
"is_default": false
},
"files": [],
"thumbnail": null
},
{
"id": "04e9d469-ac93-4c60-ba69-0ebc9cd1955b",
"user_id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"merchant_id": "6d329797-b64d-47d1-a457-4798e2b361b5",
"thumbnail_id": null,
"item": "Item 4",
"code": "item-4",
"category": "default",
"details": "details about Item 4",
"is_active": true,
"is_taxable": true,
"is_service": false,
"is_subscription": false,
"is_discount": false,
"price": 8,
"in_stock": 100,
"low_stock_alert": 10,
"meta": [],
"created_at": "2019-04-16 15:29:49",
"updated_at": "2019-04-16 15:29:49",
"deleted_at": null,
"user": {
"id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"system_admin": false,
"name": "user",
"email": "[email protected]",
"email_verification_sent_at": "2019-04-16 15:29:48",
"email_verified_at": "2019-04-16 15:29:48",
"is_api_key": false,
"acknowledgments": {
"tutorial": true
},
"created_at": "2019-04-16 15:29:48",
"updated_at": "2019-04-16 15:29:48",
"deleted_at": null,
"brand": null,
"gravatar": "//www.gravatar.com/avatar/edca79f00b23dfdc0f0eb803630be006",
"team_admin": null,
"team_enabled": null,
"team_role": null,
"merchant_options": [],
"is_default": false
},
"files": [],
"thumbnail": null
},
{
"id": "262db41c-90ed-46df-b3c3-e498807d188f",
"user_id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"merchant_id": "6d329797-b64d-47d1-a457-4798e2b361b5",
"thumbnail_id": null,
"item": "Item 5",
"code": "item-5",
"category": "default",
"details": "details about Item 5",
"is_active": true,
"is_taxable": true,
"is_service": false,
"is_subscription": false,
"is_discount": false,
"price": 10,
"in_stock": 100,
"low_stock_alert": 10,
"meta": [],
"created_at": "2019-04-16 15:29:49",
"updated_at": "2019-04-16 15:29:49",
"deleted_at": null,
"user": {
"id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"system_admin": false,
"name": "user",
"email": "[email protected]",
"email_verification_sent_at": "2019-04-16 15:29:48",
"email_verified_at": "2019-04-16 15:29:48",
"is_api_key": false,
"acknowledgments": {
"tutorial": true
},
"created_at": "2019-04-16 15:29:48",
"updated_at": "2019-04-16 15:29:48",
"deleted_at": null,
"brand": null,
"gravatar": "//www.gravatar.com/avatar/edca79f00b23dfdc0f0eb803630be006",
"team_admin": null,
"team_enabled": null,
"team_role": null,
"merchant_options": [],
"is_default": false
},
"files": [],
"thumbnail": null
},
{
"id": "afd15eb8-6556-40f5-b6ce-fd9ceb6a2251",
"user_id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"merchant_id": "6d329797-b64d-47d1-a457-4798e2b361b5",
"thumbnail_id": null,
"item": "Item 3",
"code": "item-3",
"category": "default",
"details": "details about item 3",
"is_active": true,
"is_taxable": true,
"is_service": false,
"is_subscription": false,
"is_discount": false,
"price": 20,
"in_stock": 100,
"low_stock_alert": 10,
"meta": [],
"created_at": "2019-04-16 15:29:49",
"updated_at": "2019-05-30 15:49:40",
"deleted_at": null,
"user": {
"id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"system_admin": false,
"name": "user",
"email": "[email protected]",
"email_verification_sent_at": "2019-04-16 15:29:48",
"email_verified_at": "2019-04-16 15:29:48",
"is_api_key": false,
"acknowledgments": {
"tutorial": true
},
"created_at": "2019-04-16 15:29:48",
"updated_at": "2019-04-16 15:29:48",
"deleted_at": null,
"brand": null,
"gravatar": "//www.gravatar.com/avatar/edca79f00b23dfdc0f0eb803630be006",
"team_admin": null,
"team_enabled": null,
"team_role": null,
"merchant_options": [],
"is_default": false
},
"files": [],
"thumbnail": null
},
{
"id": "c85d4614-cdab-4ba3-9ff5-087843cb10a6",
"user_id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"merchant_id": "6d329797-b64d-47d1-a457-4798e2b361b5",
"thumbnail_id": null,
"item": "Item 1",
"code": "item-1",
"category": "default",
"details": "",
"is_active": true,
"is_taxable": true,
"is_service": false,
"is_subscription": false,
"is_discount": false,
"price": 20,
"in_stock": 100,
"low_stock_alert": 10,
"meta": [],
"created_at": "2019-04-16 15:29:49",
"updated_at": "2019-05-30 15:49:25",
"deleted_at": null,
"user": {
"id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"system_admin": false,
"name": "user",
"email": "[email protected]",
"email_verification_sent_at": "2019-04-16 15:29:48",
"email_verified_at": "2019-04-16 15:29:48",
"is_api_key": false,
"acknowledgments": {
"tutorial": true
},
"created_at": "2019-04-16 15:29:48",
"updated_at": "2019-04-16 15:29:48",
"deleted_at": null,
"brand": null,
"gravatar": "//www.gravatar.com/avatar/edca79f00b23dfdc0f0eb803630be006",
"team_admin": null,
"team_enabled": null,
"team_role": null,
"merchant_options": [],
"is_default": false
},
"files": [],
"thumbnail": null
},
{
"id": "185cce0d-5c63-4d57-a773-132bf2970167",
"user_id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"merchant_id": "6d329797-b64d-47d1-a457-4798e2b361b5",
"thumbnail_id": null,
"item": "Service 1",
"code": null,
"category": null,
"details": "Details about Service 1.",
"is_active": true,
"is_taxable": false,
"is_service": true,
"is_subscription": false,
"is_discount": false,
"price": 50,
"in_stock": 0,
"low_stock_alert": null,
"meta": [],
"created_at": "2019-06-16 18:35:49",
"updated_at": "2019-06-16 18:35:49",
"deleted_at": null,
"user": {
"id": "08172f90-c2e8-41d4-be0a-4cc601cd5770",
"system_admin": false,
"name": "user",
"email": "[email protected]",
"email_verification_sent_at": "2019-04-16 15:29:48",
"email_verified_at": "2019-04-16 15:29:48",
"is_api_key": false,
"acknowledgments": {
"tutorial": true
},
"created_at": "2019-04-16 15:29:48",
"updated_at": "2019-04-16 15:29:48",
"deleted_at": null,
"brand": null,
"gravatar": "//www.gravatar.com/avatar/edca79f00b23dfdc0f0eb803630be006",
"team_admin": null,
"team_enabled": null,
"team_role": null,
"merchant_options": [],
"is_default": false
},
"files": [],
"thumbnail": null
}
],
"total": 6
},
"status": 200,
"statusText": "",
"headers": {
"content-type": "application/json",
"cache-control": "no-cache, private"
},
"request": {}
}
Loading

0 comments on commit 09baace

Please sign in to comment.