diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-06-14 16:44:21 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-06-14 16:44:21 -0400 |
| commit | b1600adec47a04f60e1da07d94a3ed3906ff5aee (patch) | |
| tree | 828f786da6806d7237ee5cbc5df61e552353b85b /finished-application/frontend/lib/testUtils.js | |
| parent | a95e08cd2dd5d7ec0a0412adae02515a5f9cec4f (diff) | |
starter files
Diffstat (limited to 'finished-application/frontend/lib/testUtils.js')
| -rw-r--r-- | finished-application/frontend/lib/testUtils.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/finished-application/frontend/lib/testUtils.js b/finished-application/frontend/lib/testUtils.js new file mode 100644 index 0000000..42739e9 --- /dev/null +++ b/finished-application/frontend/lib/testUtils.js @@ -0,0 +1,79 @@ +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 }; |
