Skip to content

Commit d3cfd03

Browse files
author
Víctor Martínez
authored
properties tests added (#17)
1 parent 9842aff commit d3cfd03

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/controllers/properties-controller.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ async function getProperty(req, res, next) {
44
const { propertyId } = req.params;
55
try {
66
const response = await getPropertyById(propertyId);
7-
res.status(200).send(response);
7+
res.status(200).send({
8+
data: response,
9+
error: null
10+
});
811
} catch (err) {
912
next(err);
1013
}
@@ -13,7 +16,10 @@ async function getProperty(req, res, next) {
1316
async function searchProperties(req, res, next) {
1417
try {
1518
const response = await searchAdminProperties(req.query);
16-
res.status(200).send(response);
19+
res.status(200).send({
20+
data: response,
21+
error: null
22+
});
1723
} catch (err) {
1824
next(err);
1925
}

src/routes/__tests__/properties-routes.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ const testServer = require("../../mock/db-test-server");
88
const app = require("../../server");
99
const setupTestDB = require("../../mock/seedTestDB");
1010
const { parseQueryParams } = require("../../utils/properties");
11+
const fetch = require("node-fetch");
12+
jest.mock("node-fetch");
1113

1214
const request = supertest(app);
1315

16+
17+
beforeEach(async () => {
18+
jest.clearAllMocks();
19+
});
20+
1421
beforeAll(async () => {
1522
await testServer.initTestServer();
1623
await setupTestDB.seedTestBookingsDB();
@@ -34,4 +41,28 @@ describe("Properties routes", () => {
3441
const string = parseQueryParams(queryParams);
3542
expect(string).toEqual("name=Patata&age=19&homeType[]=patata&homeType[]=queso&homeType[]=macarrones&names[]=Victor&names[]=Martinez&names[]=Montané&sold=true&");
3643
});
44+
45+
it("can search properties", async () => {
46+
fetch.mockResolvedValue({
47+
json: () => Promise.resolve([
48+
{ hello: "World" }
49+
]),
50+
ok: true
51+
});
52+
53+
const res = await request.get("/properties?kind=Office");
54+
expect(res.body.data).toMatchObject([{ hello: "World" }]);
55+
});
56+
57+
it("can get property by Id", async () => {
58+
fetch.mockResolvedValue({
59+
json: () => Promise.resolve(
60+
{ hello: "World" }
61+
),
62+
ok: true
63+
});
64+
65+
const res = await request.get("/properties/sdflksdgkn");
66+
expect(res.body.data).toMatchObject({ hello: "World" });
67+
});
3768
});

0 commit comments

Comments
 (0)