mirror of
https://github.com/yusufipk/RememberMe.git
synced 2026-09-11 10:56:07 +00:00
change(person/route) put, takes previous values if not specified by user
This commit is contained in:
@@ -3,6 +3,8 @@ const app = express();
|
|||||||
|
|
||||||
require("./startup/db")();
|
require("./startup/db")();
|
||||||
require("./startup/routes")(app);
|
require("./startup/routes")(app);
|
||||||
|
if (process.env.NODE_ENV !== "test") require("./startup/prod")(app);
|
||||||
|
|
||||||
const { logger } = require("./startup/logging");
|
const { logger } = require("./startup/logging");
|
||||||
|
|
||||||
const port = process.env.port || 3002;
|
const port = process.env.port || 3002;
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ function validatePerson(value) {
|
|||||||
tags: Joi.array().max(6),
|
tags: Joi.array().max(6),
|
||||||
createdAt: Joi.string().max(25),
|
createdAt: Joi.string().max(25),
|
||||||
});
|
});
|
||||||
return schema.validate(value);
|
return schema.validate(value, { allowUnknown: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Person = Person;
|
exports.Person = Person;
|
||||||
|
|||||||
Generated
+129
@@ -5,7 +5,9 @@
|
|||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"compression": "^1.7.4",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
|
"helmet": "^4.6.0",
|
||||||
"joi": "^17.4.1",
|
"joi": "^17.4.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"mongoose": "^5.13.3",
|
"mongoose": "^5.13.3",
|
||||||
@@ -1686,6 +1688,60 @@
|
|||||||
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
|
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/compressible": {
|
||||||
|
"version": "2.0.18",
|
||||||
|
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
||||||
|
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
|
||||||
|
"dependencies": {
|
||||||
|
"mime-db": ">= 1.43.0 < 2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/compression": {
|
||||||
|
"version": "1.7.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz",
|
||||||
|
"integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"accepts": "~1.3.5",
|
||||||
|
"bytes": "3.0.0",
|
||||||
|
"compressible": "~2.0.16",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"on-headers": "~1.0.2",
|
||||||
|
"safe-buffer": "5.1.2",
|
||||||
|
"vary": "~1.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/compression/node_modules/bytes": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
|
||||||
|
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/compression/node_modules/debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/compression/node_modules/ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||||
|
},
|
||||||
|
"node_modules/compression/node_modules/safe-buffer": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
|
},
|
||||||
"node_modules/concat-map": {
|
"node_modules/concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@@ -2446,6 +2502,14 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/helmet": {
|
||||||
|
"version": "4.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/helmet/-/helmet-4.6.0.tgz",
|
||||||
|
"integrity": "sha512-HVqALKZlR95ROkrnesdhbbZJFi/rIVSoNq6f3jA/9u6MIbTsPh3xZwihjeI5+DO/2sOV6HMHooXcEOuwskHpTg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/html-encoding-sniffer": {
|
"node_modules/html-encoding-sniffer": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-2.0.1.tgz",
|
||||||
@@ -3999,6 +4063,14 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/on-headers": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/once": {
|
"node_modules/once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
@@ -6676,6 +6748,53 @@
|
|||||||
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
|
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"compressible": {
|
||||||
|
"version": "2.0.18",
|
||||||
|
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
||||||
|
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
|
||||||
|
"requires": {
|
||||||
|
"mime-db": ">= 1.43.0 < 2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"compression": {
|
||||||
|
"version": "1.7.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz",
|
||||||
|
"integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==",
|
||||||
|
"requires": {
|
||||||
|
"accepts": "~1.3.5",
|
||||||
|
"bytes": "3.0.0",
|
||||||
|
"compressible": "~2.0.16",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"on-headers": "~1.0.2",
|
||||||
|
"safe-buffer": "5.1.2",
|
||||||
|
"vary": "~1.1.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"bytes": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
|
||||||
|
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
|
||||||
|
},
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||||
|
},
|
||||||
|
"safe-buffer": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@@ -7282,6 +7401,11 @@
|
|||||||
"integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==",
|
"integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"helmet": {
|
||||||
|
"version": "4.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/helmet/-/helmet-4.6.0.tgz",
|
||||||
|
"integrity": "sha512-HVqALKZlR95ROkrnesdhbbZJFi/rIVSoNq6f3jA/9u6MIbTsPh3xZwihjeI5+DO/2sOV6HMHooXcEOuwskHpTg=="
|
||||||
|
},
|
||||||
"html-encoding-sniffer": {
|
"html-encoding-sniffer": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-2.0.1.tgz",
|
||||||
@@ -8483,6 +8607,11 @@
|
|||||||
"ee-first": "1.1.1"
|
"ee-first": "1.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"on-headers": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
|
||||||
|
},
|
||||||
"once": {
|
"once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"compression": "^1.7.4",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
|
"helmet": "^4.6.0",
|
||||||
"joi": "^17.4.1",
|
"joi": "^17.4.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"mongoose": "^5.13.3",
|
"mongoose": "^5.13.3",
|
||||||
|
|||||||
@@ -72,6 +72,35 @@ router.put("/:id", auth, validateObjectId, async (req, res) => {
|
|||||||
const person = await Person.findById(req.params.id);
|
const person = await Person.findById(req.params.id);
|
||||||
if (!person) return res.status(404).send("Person does not exist!");
|
if (!person) return res.status(404).send("Person does not exist!");
|
||||||
|
|
||||||
|
const {
|
||||||
|
name,
|
||||||
|
place,
|
||||||
|
contact,
|
||||||
|
birth,
|
||||||
|
age,
|
||||||
|
likes,
|
||||||
|
dislikes,
|
||||||
|
occupation,
|
||||||
|
lastseen,
|
||||||
|
nextcontact,
|
||||||
|
notes,
|
||||||
|
tags,
|
||||||
|
} = person;
|
||||||
|
|
||||||
|
if (!req.body.name) req.body.name = name;
|
||||||
|
if (!req.body.place) req.body.place = place;
|
||||||
|
if (!req.body.contact) req.body.contact = contact;
|
||||||
|
if (!req.body.birth) req.body.birth = birth;
|
||||||
|
if (!req.body.age) req.body.age = age;
|
||||||
|
if (!req.body.likes) req.body.likes = likes;
|
||||||
|
if (!req.body.dislikes) req.body.dislikes = dislikes;
|
||||||
|
if (!req.body.occupation) req.body.occupation = occupation;
|
||||||
|
if (!req.body.lastseen) req.body.lastseen = lastseen;
|
||||||
|
if (!req.body.nextcontact) req.body.nextcontact = nextcontact;
|
||||||
|
if (!req.body.notes) req.body.notes = notes;
|
||||||
|
if (!req.body.tags) req.body.tags = tags;
|
||||||
|
|
||||||
|
console.log(req.body);
|
||||||
const { error } = validate(req.body);
|
const { error } = validate(req.body);
|
||||||
if (error) return res.status(400).send(error.details[0].message);
|
if (error) return res.status(400).send(error.details[0].message);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
const helmet = require("helmet");
|
||||||
|
const compression = require("compression");
|
||||||
|
|
||||||
|
module.exports = function (app) {
|
||||||
|
app.use(helmet());
|
||||||
|
app.use(compression());
|
||||||
|
};
|
||||||
@@ -191,9 +191,10 @@ describe("person route", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("PUT /api/person/:id", () => {
|
describe("PUT /api/person/:id", () => {
|
||||||
let person;
|
let person2;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
person = {
|
person2 = {
|
||||||
name: "Jimmy",
|
name: "Jimmy",
|
||||||
place: "Texas",
|
place: "Texas",
|
||||||
};
|
};
|
||||||
@@ -203,7 +204,7 @@ describe("person route", () => {
|
|||||||
return await request(server)
|
return await request(server)
|
||||||
.put(`/api/person/${personId}`)
|
.put(`/api/person/${personId}`)
|
||||||
.set({ "x-auth-token": token })
|
.set({ "x-auth-token": token })
|
||||||
.send(person);
|
.send(person2);
|
||||||
};
|
};
|
||||||
|
|
||||||
it("should return 401 if no token provided", async () => {
|
it("should return 401 if no token provided", async () => {
|
||||||
@@ -224,18 +225,6 @@ describe("person route", () => {
|
|||||||
expect(res.status).toBe(404);
|
expect(res.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("joi should return 400 if input is invalid", async () => {
|
|
||||||
person.name = "";
|
|
||||||
const res = await exec();
|
|
||||||
expect(res.status).toBe(400);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("joi should return 400 if input is invalid", async () => {
|
|
||||||
person.place = "";
|
|
||||||
const res = await exec();
|
|
||||||
expect(res.status).toBe(400);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return 200 if input is valid", async () => {
|
it("should return 200 if input is valid", async () => {
|
||||||
const res = await exec();
|
const res = await exec();
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
|
|||||||
Reference in New Issue
Block a user