Repository navigation
Expand file tree
/
Copy pathserverTests.test.js
More file actions
102 lines (86 loc) · 4.15 KB
/
Copy pathserverTests.test.js
File metadata and controls
102 lines (86 loc) · 4.15 KB
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
const axios = require('axios');
const { assert, expect } = require('chai');
const mongoose = require('mongoose');
const { sampleQuestionsAPIData, sampleAnswersAPIData, sampleQuestionsDBData, sampleAnswersDBData, sampleAnswersPhotosDBData } = require('../sampleData.js');
const { Questions, Answers, AnswersPhotos } = require('../database/mongoSchema.js');
let server, db;
describe('Server Tests', () => {
beforeEach((done) => {
const app = require('../server/index.js');
server = app.server;
const database = require('../database/index.js');
db = database.db;
done();
});
describe('GET /qa/questions', (done) => {
jest.setTimeout(10000);
it('should get the expected shape of data from the query', () => {
return axios.get('http://localhost:3000/qa/questions?product_id=1')
.then(response => {
expect(response.data).to.be.a('object');
assert.property(response.data, 'product', 'has property "product"');
assert.property(response.data, 'results', 'has property "results"');
const results = response.data.results;
assert.isArray(results);
assert.property(results[0], 'question_id', 'results[0] has property "question_id"');
assert.property(results[0], 'question_body', 'results[0] has property "question_body"');
assert.property(results[0], 'question_date', 'results[0] has property "question_date"');
assert.property(results[0], 'asker_name', 'results[0] has property "asker_name"');
assert.property(results[0], 'question_helpfulness', 'results[0] has property "question_helpfulness"');
assert.property(results[0], 'reported', 'results[0] has property "reported"');
assert.property(results[0], 'answers', 'results[0] has property "answers"');
assert.isArray(results[0].answers);
expect(results[0]).reported.to.be(false);
done();
})
.catch(() => done);
});
});
// describe('POST /qa/questions', () => {
// it('should return "Successfully added question"', () => {
// })
// });
describe('GET /qa/answers', (done) => {
it('should get the expected shape of data from the query', () => {
return axios.get('http://localhost:3000/qa/answers?question_id=1')
.then(response => {
expect(response.data).to.be.a('object');
assert.property(response.data, 'question', 'has property "question"');
assert.property(response.data,'page', 'has property "page"');
assert.property(response.data, 'count', 'has property "count"');
assert.property(response.data, 'results', 'has property "results"');
const results = response.data.results;
assert.isArray(results);
assert.property(results[0], 'answer_id', 'results[0] has property "answer_id"');
assert.property(results[0], 'body', 'results[0] has property "body"');
assert.property(results[0], 'date', 'results[0] has property "date"');
assert.property(results[0], 'answerer_name', 'results[0] has property "answerer_name"');
assert.property(results[0], 'helpfulness', 'results[0] has property "helpfulness"');
assert.property(results[0], 'photos', 'results[0] has property "photos"');
assert.isArray(results[0].photos);
done();
})
.catch(() => done);
});
});
// describe('POST /qa/questions/:question_id/answers', () => {
// // Post some fake data, then delete the fake data
// });
// describe('PUT /qa/questions/:question_id/helpful', () => {
// // Put data (mark question as helpful, then decrement)
// });
// describe('PUT /qa/answers/:answer_id/helpful', () => {
// // Put data (mark answer as helpful, then decrement)
// });
// describe('PUT /qa/questions/:question_id/report', () => {
// // Put data (mark question as reported, must be a previously unreported question, then decrement)
// });
// describe('PUT /qa/answers/:answer_id/report', () => {
// // Put data (mark answer as reported, must be a previously unreported answer, then decrement)
// });
afterEach((done) => {
db.disconnect();
server.close();
done();
});
});