forked from 2011-team-kungfutea/grace-shopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.spec.js
322 lines (267 loc) · 10.8 KB
/
test.spec.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// /* global describe beforeEach afterEach it */
// import {expect} from 'chai'
// import {me, logout} from './client/store/user'
// import {fetchUsers} from './client/store/all-users-reducer'
// import {checkoutThunk, guestCheckoutThunk, emptyCart} from './client/store/cart-reducer'
// import axios from 'axios'
// import MockAdapter from 'axios-mock-adapter'
// import configureMockStore from 'redux-mock-store'
// import thunkMiddleware from 'redux-thunk'
// import history from '../node_modules/history'
// const middlewares = [thunkMiddleware]
// const mockStore = configureMockStore(middlewares)
// describe('thunk creators', () => {
// let store
// let mockAxios
// const initialState = {user: {}}
// beforeEach(() => {
// mockAxios = new MockAdapter(axios)
// store = mockStore(initialState)
// })
// afterEach(() => {
// mockAxios.restore()
// store.clearActions()
// })
// describe('checkoutThunk', () => {
// it('creates a new order', async () => {
// })
// })
// describe('guestCheckoutThunk', () => {
// it('creates a new order and calls emptyCart', async () => {
// })
// })
//-----------------------------------
// describe('me', () => {
// it('eventually dispatches the GET USER action', async () => {
// const fakeUser = {email: 'Cody'}
// mockAxios.onGet('/auth/me').replyOnce(200, fakeUser)
// await store.dispatch(me())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('GET_USER')
// expect(actions[0].user).to.be.deep.equal(fakeUser)
// })
// })
// describe('logout', () => {
// it('logout: eventually dispatches the REMOVE_USER action', async () => {
// mockAxios.onPost('/auth/logout').replyOnce(204)
// await store.dispatch(logout())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('REMOVE_USER')
// expect(history.location.pathname).to.be.equal('/login')
// })
// })
// describe('fetchUsers', () => {
// it('going to Users view as admin dispatches the FETCH_USERS action', async () => {
// const afakeUser = {email: 'Cody'}
// mockAxios.onGet('/api/users').replyOnce(200, afakeUser)
// await store.dispatch(fetchUsers())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('GET_USERS')
// expect(history.location.pathname).to.be.equal('/login')
// })
// })
// })
// const {expect} = require('chai')
// const db = require('./server/db/index')
// const User = db.model('user')
// describe('User model', () => {
// beforeEach(() => {
// return db.sync({force: true})
// })
// describe('instanceMethods', () => {
// describe('correctPassword', () => {
// let cody
// beforeEach(async () => {
// cody = await User.create({
// email: 'cody@puppybook.com',
// password: 'bones'
// })
// })
// it('returns true if the password is correct', () => {
// expect(cody.correctPassword('bones')).to.be.equal(true)
// })
// it('returns false if the password is incorrect', () => {
// expect(cody.correctPassword('bonez')).to.be.equal(false)
// })
// }) // end describe('correctPassword')
// }) // end describe('instanceMethods')
// }) // end describe('User model')
// /* global describe beforeEach it */
// /*As a guest:
// - have an empty cart when I first navigate to the URL*/
// describe('thunk creators', () => {
// let store
// let mockAxios
// const initialState = {user: {}}
// beforeEach(() => {
// mockAxios = new MockAdapter(axios)
// store = mockStore(initialState)
// })
// afterEach(() => {
// mockAxios.restore()
// store.clearActions()
// })
// describe('me', () => {
// it('returns an empty user when a user first navigates to the page', async () => {
// describe('getUsers', () => {
// it('going to Users view as admin dispatches the FETCH_USERS action', async () => {
// const emptyUser = {}
// mockAxios.onGet('/auth/me').replyOnce(200, emptyUser)
// await store.dispatch(getUsers())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('GET_USERS')
// // expect(history.location.pathname).to.be.equal('/login')
// })
// })
// })
// })
// })
// export const me = () => async dispatch => {
// try {
// const res = await axios.get('/auth/me')
// dispatch(getUser(res.data || defaultUser))
// } catch (err) {
// console.error(err)
// }
// }
// it('have an empty cart when user navigates to the page', async () => {
// mockAxios.onGet('/auth/me').replyOnce(200, fakeUser)
// await store.dispatch(me())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('GET_USER')
// expect(actions[0].user).to.be.deep.equal(fakeUser)
// })
// describe('logout', () => {
// it('logout: eventually dispatches the REMOVE_USER action', async () => {
// mockAxios.onPost('/auth/logout').replyOnce(204)
// await store.dispatch(logout())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('REMOVE_USER')
// expect(history.location.pathname).to.be.equal('/login')
// })
// })
// /*- I have links that navigate to view: home, all products, cart, login, sign up
// -I can view all products when I click the cart it shows an empty cart
// - when I click home it takes me to the home page
// - when I click adopt I can see all products
// - when I click on a product it takes me to a single product page
// - on the single product page I can add that product to my cart
// - the cart icon will update and I can click that to view my cart items
// -on the cart page I can delete products from my cart
// - I can checkout — takes me to checkout page where I can fill out my info with validation which will send my order and give me a new empty cart (make sure email is unique)
// -persists in database (?)
// Logged in as admin:
// - have the same navigation as guest but login/ sign up has changed to be just log out
// - my cart persists from the last time I was logged in */
// /*- I have a User view that shows me all users
// - I can view all products under adopt AND I have a button for adding/ editing/ and deleting a product
// I am able to add, edit and delete a product
// - I can add to and delete products from my cart
// - when I go to checkout any info on file for me will auto populate in the form
// - my order will persist in the database and I will have a new empty cart ready to add more products
// Sign up
// - I can sign up with a unique email
// - it doesn’t let me sign up with a taken email
// - it doesn’t let me sign up as an admin
// I have the same navigation as the admin logged in user but I don’t have the user view or the add/ edit/ delete product views
// I can add/ delete and edit things in my cart
// when I go to checkout any info on file for me will auto populate in the form
// - my order will persist in the database and I will have a new empty cart ready to add more products
// Logged in
// - when I log back in my cart is still at the value where I left it
// -I can add/ edit quantity and delete things from my cart
// when I go to checkout any info on file for me will auto populate in the form
// - if I don’t fill in all fields it will not let me check out (DONT EDIT EMAIL)
// - my order will persist in the database and I will have a new empty cart ready to add more products
// Add descriptions so the prices make sense
// - on checkout change the view
// - get rid of outdated delete route
// - google Oauth, mostly set up
// - tests: cart persistence based on user state
// -refactor add to products button based on history
// - if history works, add it to checkout
// Routes:
// Tests:
// -is there a cart when user is logged in
// - is there only a cart in state when the user is a guest
// - no associated order-details row
// -is an order row created on checkout
// Is a new cart created on checkout
// Does add to cart update the cart state and the icon/ logged in/ guest */
// describe('User routes', () => {
// beforeEach(() => {
// return db.sync({force: true})
// })
// describe('/api/users/', () => {
// const codysEmail = 'cody@puppybook.com'
// beforeEach(() => {
// return User.create({
// email: codysEmail
// })
// })
// it('GET /api/users', async () => {
// const res = await request(app)
// .get('/api/users')
// .expect(200)
// expect(res.body).to.be.an('array')
// expect(res.body[0].email).to.be.equal(codysEmail)
// })
// }) // end describe('/api/users')
// }) // end describe('User routes')
// const adapter = new Adapter()
// enzyme.configure({adapter})
// describe('UserHome', () => {
// let userHome
// beforeEach(() => {
// userHome = shallow(<UserHome email="cody@email.com" />)
// })
// // it('renders the email in an h1', () => {
// // expect(userHome.find('h1').text()).to.be.equal('Welcome, cody@email.com')
// // })
// })
// describe('thunk creators', () => {
// let store
// let mockAxios
// const initialState = {user: {}}
// beforeEach(() => {
// mockAxios = new MockAdapter(axios)
// store = mockStore(initialState)
// })
// afterEach(() => {
// mockAxios.restore()
// store.clearActions()
// })
// describe('me', () => {
// it('eventually dispatches the GET USER action', async () => {
// const fakeUser = {email: 'Cody'}
// mockAxios.onGet('/auth/me').replyOnce(200, fakeUser)
// await store.dispatch(me())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('GET_USER')
// expect(actions[0].user).to.be.deep.equal(fakeUser)
// })
// })
// describe('logout', () => {
// it('logout: eventually dispatches the REMOVE_USER action', async () => {
// mockAxios.onPost('/auth/logout').replyOnce(204)
// await store.dispatch(logout())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('REMOVE_USER')
// expect(history.location.pathname).to.be.equal('/login')
// })
// })
// describe('fetchUsers', () => {
// it('going to Users view as admin dispatches the FETCH_USERS action', async () => {
// const afakeUser = {email: 'Cody'}
// mockAxios.onGet('/api/users').replyOnce(200, afakeUser)
// await store.dispatch(fetchUsers())
// const actions = store.getActions()
// expect(actions[0].type).to.be.equal('GET_USERS')
// // expect(history.location.pathname).to.be.equal('/login')
// })
// })
// })
// const seed = require('./seed')
// describe('seed script', () => {
// it('completes successfully', seed)
// })