diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-09-13 14:18:56 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-09-13 14:18:56 -0400 |
| commit | 8a5825d52271d712ec7c8348447d433067e13ef2 (patch) | |
| tree | ba07c218c1b2d4e59c154f2059b69fd858ae65fe /finished-application/frontend/lib | |
| parent | b0d25a9ad3cc1df2fcc11ddb84e4603b94520b09 (diff) | |
DONE
Diffstat (limited to 'finished-application/frontend/lib')
| -rw-r--r-- | finished-application/frontend/lib/calcTotalPrice.js | 6 | ||||
| -rw-r--r-- | finished-application/frontend/lib/formatMoney.js | 11 | ||||
| -rw-r--r-- | finished-application/frontend/lib/testUtils.js | 79 | ||||
| -rw-r--r-- | finished-application/frontend/lib/withData.js | 35 |
4 files changed, 0 insertions, 131 deletions
diff --git a/finished-application/frontend/lib/calcTotalPrice.js b/finished-application/frontend/lib/calcTotalPrice.js deleted file mode 100644 index 4822468..0000000 --- a/finished-application/frontend/lib/calcTotalPrice.js +++ /dev/null @@ -1,6 +0,0 @@ -export default function calcTotalPrice(cart) { - return cart.reduce((tally, cartItem) => { - if (!cartItem.item) return tally; - return tally + cartItem.quantity * cartItem.item.price; - }, 0); -} diff --git a/finished-application/frontend/lib/formatMoney.js b/finished-application/frontend/lib/formatMoney.js deleted file mode 100644 index c001aee..0000000 --- a/finished-application/frontend/lib/formatMoney.js +++ /dev/null @@ -1,11 +0,0 @@ -export default function(amount) { - const options = { - style: 'currency', - currency: 'USD', - minimumFractionDigits: 2, - }; - // if its a whole, dollar amount, leave off the .00 - if (amount % 100 === 0) options.minimumFractionDigits = 0; - const formatter = new Intl.NumberFormat('en-US', options); - return formatter.format(amount / 100); -} diff --git a/finished-application/frontend/lib/testUtils.js b/finished-application/frontend/lib/testUtils.js deleted file mode 100644 index 42739e9..0000000 --- a/finished-application/frontend/lib/testUtils.js +++ /dev/null @@ -1,79 +0,0 @@ -import casual from 'casual'; - -// seed it so we get consistent results -casual.seed(777); - -const fakeItem = () => ({ - __typename: 'Item', - id: '123', - price: 5000, - user: null, - image: 'dog-small.jpg', - title: 'dogs are best', - description: 'dogs', - largeImage: 'dog.jpg', -}); - -const fakeUser = () => ({ - __typename: 'User', - id: '4234', - name: casual.name, - email: casual.email, - permissions: ['ADMIN'], - orders: [], - cart: [], -}); - -const fakeOrderItem = () => ({ - __typename: 'OrderItem', - id: casual.uuid, - image: `${casual.word}.jpg`, - title: casual.words(), - price: 4234, - quantity: 1, - description: casual.words(), -}); - -const fakeOrder = () => ({ - __typename: 'Order', - id: 'ord123', - charge: 'ch_123', - total: 40000, - items: [fakeOrderItem(), fakeOrderItem()], - createdAt: '2018-04 - 06T19: 24: 16.000Z', - user: fakeUser(), -}); - -const fakeCartItem = overrides => ({ - __typename: 'CartItem', - id: 'omg123', - quantity: 3, - item: fakeItem(), - user: fakeUser(), - ...overrides, -}); - -// Fake LocalStorage -class LocalStorageMock { - constructor() { - this.store = {}; - } - - clear() { - this.store = {}; - } - - getItem(key) { - return this.store[key] || null; - } - - setItem(key, value) { - this.store[key] = value.toString(); - } - - removeItem(key) { - delete this.store[key]; - } -} - -export { LocalStorageMock, fakeItem, fakeUser, fakeCartItem, fakeOrder, fakeOrderItem }; diff --git a/finished-application/frontend/lib/withData.js b/finished-application/frontend/lib/withData.js deleted file mode 100644 index 0256ba9..0000000 --- a/finished-application/frontend/lib/withData.js +++ /dev/null @@ -1,35 +0,0 @@ -import withApollo from 'next-with-apollo'; -import ApolloClient from 'apollo-boost'; -import { LOCAL_STATE_QUERY } from '../components/Cart'; -import { endpoint } from '../config'; - -function createClient({ headers }) { - return new ApolloClient({ - uri: process.env.NODE_ENV === 'development' ? endpoint : endpoint, - request: operation => { - operation.setContext({ - fetchOptions: { - credentials: 'include', - }, - headers, - }); - }, - clientState: { - resolvers: { - Mutation: { - toggleCart(_, variables, { cache }) { - const { cartOpen } = cache.readQuery({ query: LOCAL_STATE_QUERY }); - const data = { data: { cartOpen: !cartOpen } }; - cache.writeData(data); - return data; - }, - }, - }, - defaults: { - cartOpen: false, - }, - }, - }); -} - -export default withApollo(createClient); |
