Skip to content

Commit b17bada

Browse files
Tests created(need to be corrected)
1 parent 7219784 commit b17bada

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

tests/hacker.test.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ describe("PATCH update one hacker", function() {
593593
});
594594
});
595595

596+
//should FAIL on authentication
596597
it("should FAIL to accept a hacker on /api/hacker/accept/:id due to authentication", function(done) {
597598
chai.request(server.app)
598599
.patch(`/api/hacker/accept/${TeamHacker0._id}`)
@@ -685,6 +686,98 @@ describe("PATCH update one hacker", function() {
685686
});
686687
});
687688

689+
it("should FAIL to accept a hacker on /api/hacker/acceptEmail/:email due to authentication", function(done) {
690+
chai.request(server.app)
691+
.patch(`/api/hacker/acceptEmail/${teamHackerAccount0.email}`)
692+
.type("application/json")
693+
.send()
694+
.end(function(err, res) {
695+
res.should.have.status(401);
696+
res.should.be.json;
697+
res.body.should.have.property("message");
698+
res.body.message.should.equal(Constants.Error.AUTH_401_MESSAGE);
699+
done();
700+
});
701+
});
702+
703+
// should FAIL due to authorization
704+
it("should FAIL to accept hacker info due to lack of authorization on /api/hacker/acceptEmail/:email", function(done) {
705+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
706+
if (error) {
707+
agent.close();
708+
return done(error);
709+
}
710+
return agent
711+
.patch(`/api/hacker/acceptEmail/${teamHackerAccount0.email}`)
712+
.type("application/json")
713+
.send()
714+
.end(function(err, res) {
715+
res.should.have.status(403);
716+
res.should.be.json;
717+
res.body.should.have.property("message");
718+
res.body.message.should.equal(
719+
Constants.Error.AUTH_403_MESSAGE
720+
);
721+
res.body.should.have.property("data");
722+
723+
done();
724+
});
725+
});
726+
});
727+
728+
it("should FAIL to accept an invalid hacker's info on /api/hacker/acceptEmail/:email", function(done) {
729+
util.auth.login(agent, Admin0, (error) => {
730+
if (error) {
731+
agent.close();
732+
return done(error);
733+
}
734+
return agent
735+
.patch(`/api/hacker/acceptEmail/${invalidHacker1.email}`)
736+
.type("application/json")
737+
.send()
738+
.end(function(err, res) {
739+
res.should.have.status(404);
740+
res.should.be.json;
741+
res.body.should.have.property("message");
742+
res.body.message.should.equal(
743+
Constants.Error.HACKER_404_MESSAGE
744+
);
745+
res.body.should.have.property("data");
746+
747+
done();
748+
});
749+
});
750+
});
751+
752+
it("should SUCCEED and accept a hacker on /api/hacker/acceptEmail/:email as an Admin", function(done) {
753+
util.auth.login(agent, Admin0, (error) => {
754+
if (error) {
755+
agent.close();
756+
return done(error);
757+
}
758+
return agent
759+
.patch(`/api/hacker/acceptEmail/${TeamHacker0.email}`)
760+
.type("application/json")
761+
.send()
762+
.end(function(err, res) {
763+
res.should.have.status(200);
764+
res.should.be.json;
765+
res.body.should.have.property("message");
766+
res.body.message.should.equal(
767+
Constants.Success.HACKER_UPDATE
768+
);
769+
res.body.should.have.property("data");
770+
chai.assert.equal(
771+
JSON.stringify(res.body.data),
772+
JSON.stringify({
773+
status: "Accepted"
774+
})
775+
);
776+
done();
777+
});
778+
});
779+
});
780+
688781
// should succeed on admin case
689782
it("should SUCCEED and update a hacker using admin power", function(done) {
690783
util.auth.login(agent, Admin0, (error) => {

0 commit comments

Comments
 (0)