-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from DamyanBG/development
Development
- Loading branch information
Showing
2 changed files
with
154 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
const mockingoose = require('mockingoose'); | ||
const Homes = require('../../models/Homes'); | ||
const User = require('../../models/User'); | ||
const request = require('supertest'); | ||
const app = require('../../app'); | ||
|
||
describe('Positive POST /home', () => { | ||
beforeEach(() => { | ||
mockingoose.resetAll(); | ||
mockingoose(User).toReturn( | ||
{ | ||
_id: '632beab54298559b57ff172f', | ||
first_name: 'John', | ||
last_name: 'Doe', | ||
email: '[email protected]', | ||
phone_number: '34343434', | ||
role: 'admin', | ||
password: '123adminsffe', | ||
}, | ||
'findOne' | ||
); | ||
mockingoose(Homes).toReturn( | ||
{ | ||
_id: '652beab54298559b57ff172f', | ||
|
@@ -40,6 +53,7 @@ describe('Positive POST /home', () => { | |
latitude: '50', | ||
owner_id: '632beab54298559b57ff172f', | ||
}); | ||
console.log(res.body) | ||
expect(res.status).toEqual(201); | ||
expect(res.body.title).toEqual('Nice house'); | ||
expect(res.body.city).toEqual('Dobrich'); | ||
|
@@ -53,3 +67,22 @@ describe('Positive POST /home', () => { | |
expect(res.body.latitude).toEqual('50'); | ||
}); | ||
}); | ||
|
||
describe("Negative POST /home", () => { | ||
it('should not create new home without owner_id', async () => { | ||
const res = await request(app).post('/home').send({ | ||
title: 'Nice house', | ||
city: 'Dobrich', | ||
neighborhood: 'Drujba', | ||
address: 'Blok 42 A 2 8', | ||
price: '10000', | ||
size: '150', | ||
year: '1960', | ||
description: 'Really nice house, have 2 rooms', | ||
longitude: '30', | ||
latitude: '50', | ||
}) | ||
expect(res.status).toEqual(400); | ||
expect(res.body).toEqual('Invalid owner!'); | ||
}) | ||
}) |