Skip to content

Commit

Permalink
added test cases for new route
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasosmium committed Nov 18, 2024
1 parent 9fba93b commit 98e6607
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion test/integration/arts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ const artData = require("../fixtures/arts/arts")();

const config = require("config");
const cookieName = config.get("userToken.cookieName");
const { addJoinData } = require("../../models/users");
const joinData = require("../fixtures/user/join");

chai.use(chaiHttp);

describe("Arts", function () {
let jwt;
let userId = "";

beforeEach(async function () {
const userId = await addUser();
userId = await addUser();
jwt = authService.generateAuthToken({ userId });
await arts.addArt(artData[0], userId);
});
Expand Down Expand Up @@ -138,4 +141,51 @@ describe("Arts", function () {
});
});
});

describe("GET /arts/:userId", function () {
beforeEach(async function () {
await addJoinData(joinData(userId)[0]);
});

it("Should get all the arts of the user", function (done) {
chai
.request(app)
.get(`/arts/${userId}?dev=true`)
.set("cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res).to.have.status(200);
expect(res.body).to.be.a("object");
expect(res.body.message).to.equal(`User Arts of userId ${userId} returned successfully`);
expect(res.body.arts).to.be.a("array");
expect(res.body.arts[0]).to.be.a("object");
expect(res.body.arts[0].title).to.equal(artData[0].title);

return done();
});
});

it("Should return 401, for Unauthenticated User", function (done) {
chai
.request(app)
.get(`/arts/${userId}?dev=true`)
.end((err, res) => {
if (err) {
return done(err);
}

expect(res).to.have.status(401);
expect(res.body).to.be.a("object");
expect(res.body).to.deep.equal({
statusCode: 401,
error: "Unauthorized",
message: "Unauthenticated User",
});

return done();
});
});
});
});

0 comments on commit 98e6607

Please sign in to comment.