Skip to content

Commit 7433dff

Browse files
authored
Merge pull request #106 from World-of-Code/f/testLocation
added location test
2 parents 46074cb + 3bafdea commit 7433dff

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

server/api/locations/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ router.param('id', (req, res, next, id) => {
2121

2222
// // get location by url
2323
router.post('/', (req, res, next) => {
24-
Location.findOne({ where: { url: req.body.location } })
25-
.then(location => res.send(location))
24+
Location.findOne({ where: { url: req.body.locations } })
25+
.then(location => {
26+
//console.log("location", location)
27+
res.send(location)
28+
})
2629
.catch(next)
2730
})
2831

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { expect } = require('chai')
2+
const supertest = require('supertest')
3+
const db = require('../../db')
4+
const app = require('../../')
5+
const Location = db.model('location')
6+
7+
describe('Location routes', () => {
8+
let agent;
9+
beforeEach(() => {
10+
agent = supertest(app);
11+
return db.sync({ force: true })
12+
})
13+
14+
describe('/api/locations', () => {
15+
const url = 'https://www.youtube.com/watch?v=BMUiFMZr7vk'
16+
17+
beforeEach(() => {
18+
return Location.create({ url })
19+
})
20+
21+
22+
it('POST /api/locations', () => {
23+
return agent
24+
.post('/api/locations')
25+
.send({
26+
locations: 'https://www.youtube.com/watch?v=BMUiFMZr7vk'
27+
})
28+
.expect(200)
29+
.then(res => {
30+
const createLocations = res.body;
31+
//console.log("CREATE", createLocations)
32+
return Location.findById(createLocations.id)
33+
})
34+
.then(foundLocation => {
35+
console.log("FOUND", foundLocation)
36+
expect(foundLocation.url).to.be.equal('https://www.youtube.com/watch?v=BMUiFMZr7vk');
37+
})
38+
})
39+
})
40+
})
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { expect } = require('chai')
2+
const db = require('../../index')
3+
const Location = db.model('location')
4+
5+
describe('Location model', () => {
6+
beforeEach(() => {
7+
return db.sync({force: true})
8+
})
9+
10+
describe('Model', () => {
11+
describe('url', () => {
12+
let page;
13+
const url = 'https://www.youtube.com/watch?v=BMUiFMZr7vk'
14+
15+
beforeEach(() => {
16+
return Location.create({url})
17+
18+
.then(location => {
19+
page = location
20+
})
21+
})
22+
23+
it('tests model type', () => {
24+
expect(page.url).to.be.equal('https://www.youtube.com/watch?v=BMUiFMZr7vk')
25+
})
26+
})
27+
})
28+
29+
describe('location url type validation', () => {
30+
let url
31+
32+
beforeEach(() => {
33+
url = Location.build({
34+
url: 'test'
35+
})
36+
})
37+
38+
it('throw an validation error when location is not an url', () => {
39+
return url.validate()
40+
.then(() => {
41+
throw new Error('validation should fail when content is less than 10 words')
42+
}, (result) => {
43+
expect(result).to.be.an.instanceOf(Error);
44+
})
45+
})
46+
})
47+
})

0 commit comments

Comments
 (0)