diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-03-20 14:48:34 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-03-20 14:48:34 -0400 |
| commit | 92f612a995c54f7423bd2b760fb1a324044693a6 (patch) | |
| tree | 0350ceb82c0539bcafdded837c435ee68d6257ef | |
| parent | 217cfed064989816fbffcb1e285134c8e03ef5c7 (diff) | |
Starting testing
| -rw-r--r-- | backend/__tests__/item.test.js (renamed from backend/tests/item.test.js) | 0 | ||||
| -rw-r--r-- | backend/src/index.js | 4 | ||||
| -rw-r--r-- | backend/src/resolvers/Mutation.js | 7 | ||||
| -rw-r--r-- | frontend/__tests__/Cart.test.js | 15 | ||||
| -rw-r--r-- | frontend/__tests__/__snapshots__/Cart.test.js.snap | 44 |
5 files changed, 57 insertions, 13 deletions
diff --git a/backend/tests/item.test.js b/backend/__tests__/item.test.js index 0e47419..0e47419 100644 --- a/backend/tests/item.test.js +++ b/backend/__tests__/item.test.js diff --git a/backend/src/index.js b/backend/src/index.js index 3630b74..522fcfe 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -30,7 +30,9 @@ const server = new GraphQLServer({ // next(); // }); -server.start(() => console.log('Server is running on http://localhost:4000')); +server.start(deets => { + console.log(`Server is running on http://localhost:${deets.port}`); +}); // overwrite console.log const chalk = require('chalk'); diff --git a/backend/src/resolvers/Mutation.js b/backend/src/resolvers/Mutation.js index cd25599..6eeab7c 100644 --- a/backend/src/resolvers/Mutation.js +++ b/backend/src/resolvers/Mutation.js @@ -1,6 +1,5 @@ const bcrypt = require('bcryptjs'); const jwt = require('jsonwebtoken'); -const { forwardTo } = require('prisma-binding'); const { getUserId, Context } = require('../utils'); const { randomBytes } = require('crypto'); const { promisify } = require('util'); @@ -137,7 +136,6 @@ const mutations = { if (!user) { throw new Error(`No user with the email ${args.email}`); } - console.log(user); // 2. Set a reset token, and a reset date const resetToken = (await promisify(randomBytes)(20)).toString('hex'); const resetTokenExpiry = Date.now() + 3600000; // 1 hour from now @@ -151,11 +149,12 @@ const mutations = { // 3. Send them their token via email const mailRes = await mail.sendMail({ from: 'wesbos@gmail.com', - to: 'wesbos@gmail.com', + to: user.email, subject: 'Your password reset token', + // TODO: don't hardcore localhost here html: `Here is your reset link: http://localhost:3000/reset?resetToken=${resetToken}`, }); - + console.log(mailRes); return res.updateUser; }, diff --git a/frontend/__tests__/Cart.test.js b/frontend/__tests__/Cart.test.js index 0936e97..1e7d7f5 100644 --- a/frontend/__tests__/Cart.test.js +++ b/frontend/__tests__/Cart.test.js @@ -2,6 +2,7 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; import toJSON from 'enzyme-to-json'; import { Cart } from '../components/Cart'; +import { UIProvider } from '../components/UIContext'; const cartItem = { item: { price: 5000 }, @@ -17,14 +18,12 @@ const currentUser = { describe('<Cart/>', () => { it('renders', () => { - const wrapper = shallow(<Cart currentUser={currentUser} />); - }); + const wrapper = mount( + <UIProvider> + <Cart currentUser={currentUser} /> + </UIProvider> + ); - xit('opens', () => { - const wrapper = shallow(<Cart currentUser={currentUser} />); - expect('wes').toEqual('figure out how to call test context'); + expect(toJSON(wrapper)).toMatchSnapshot(); }); - // it('renders', () => { - // shallow(<Cart currentUser={currentUserLoggedOut} />); - // }); }); diff --git a/frontend/__tests__/__snapshots__/Cart.test.js.snap b/frontend/__tests__/__snapshots__/Cart.test.js.snap new file mode 100644 index 0000000..b2b6bc7 --- /dev/null +++ b/frontend/__tests__/__snapshots__/Cart.test.js.snap @@ -0,0 +1,44 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`<Cart/> renders 1`] = ` +<[object Object] + value={ + Object { + "state": Object { + "isCartOpen": false, + }, + "toggle": [Function], + } + } +> + <Cart + currentUser={ + Object { + "me": Object { + "cart": Array [ + Object { + "item": Object { + "price": 5000, + }, + "quantity": 10, + }, + Object { + "item": Object { + "price": 5000, + }, + "quantity": 10, + }, + Object { + "item": Object { + "price": 5000, + }, + "quantity": 10, + }, + ], + }, + "refetch": [Function], + } + } + /> +</[object Object]> +`; |
