@@ -41,171 +41,171 @@ const duplicateAccountLinkHacker0 = util.hacker.duplicateAccountLinkHacker0;
4141
4242const invalidHacker1 = util . hacker . invalidHacker1 ;
4343
44- // describe("GET hacker", function () {
45- // // fail on authentication
46- // it("should fail to list a hacker's information on /api/hacker/:id GET due to authentication", function (done) {
47- // chai.request(server.app)
48- // .get(`/api/hacker/` + TeamHacker0._id)
49- // .end(function (err, res) {
50- // res.should.have.status(401);
51- // res.should.be.json;
52- // res.body.should.have.property("message");
53- // res.body.message.should.equal(Constants.Error.AUTH_401_MESSAGE);
54- // done();
55- // });
56- // });
57-
58- // // success case
59- // it("should list the user's hacker info on /api/hacker/self GET", function (done) {
60- // util.auth.login(agent, teamHackerAccount0, (error) => {
61- // if (error) {
62- // agent.close();
63- // return done(error);
64- // }
65- // return agent
66- // .get("/api/hacker/self")
67- // .end(function (err, res) {
68- // if (err) {
69- // return done(err);
70- // }
71- // res.should.have.status(200);
72- // res.should.be.json;
73- // res.body.should.have.property("message");
74- // res.body.message.should.equal(Constants.Success.HACKER_READ);
75- // res.body.should.have.property("data");
76-
77- // let hacker = new Hacker(TeamHacker0);
78- // chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify(hacker.toJSON()));
79- // done();
80- // });
81- // });
82- // });
83-
84- // // fail case due to wrong account type
85- // it("should fail to list the hacker info of an admin due to wrong account type /api/account/self GET", function (done) {
86- // util.auth.login(agent, Admin0, (error) => {
87- // if (error) {
88- // agent.close();
89- // return done(error);
90- // }
91- // return agent
92- // .get("/api/hacker/self")
93- // .end(function (err, res) {
94- // res.should.have.status(409);
95- // res.should.be.json;
96- // res.body.should.have.property("message");
97- // res.body.message.should.equal(Constants.Error.ACCOUNT_TYPE_409_MESSAGE);
98- // done();
99- // });
100- // });
101- // });
102-
103- // // succeed on admin case
104- // it("should list a hacker's information using admin power on /api/hacker/:id GET", function (done) {
105- // util.auth.login(agent, Admin0, (error) => {
106- // if (error) {
107- // agent.close();
108- // return done(error);
109- // }
110- // return agent
111- // .get(`/api/hacker/${TeamHacker0._id}`)
112- // // does not have password because of to stripped json
113- // .end(function (err, res) {
114- // if (err) {
115- // return done(err);
116- // }
117- // res.should.have.status(200);
118- // res.should.be.json;
119- // res.body.should.have.property("message");
120- // res.body.message.should.equal(Constants.Success.HACKER_READ);
121- // res.body.should.have.property("data");
122-
123- // let hacker = new Hacker(TeamHacker0);
124- // chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify(hacker.toJSON()));
125-
126- // done();
127- // });
128- // });
129- // });
130-
131- // // succeed on :self case
132- // it("should list the user's hacker information on /api/hacker/:id GET", function (done) {
133- // util.auth.login(agent, teamHackerAccount0, (error) => {
134- // if (error) {
135- // agent.close();
136- // return done(error);
137- // }
138- // return agent
139- // .get(`/api/hacker/${TeamHacker0._id}`)
140- // // does not have password because of to stripped json
141- // .end(function (err, res) {
142- // if (err) {
143- // return done(err);
144- // }
145- // res.should.have.status(200);
146- // res.should.be.json;
147- // res.body.should.have.property("message");
148- // res.body.message.should.equal(Constants.Success.HACKER_READ);
149- // res.body.should.have.property("data");
150-
151- // let hacker = new Hacker(TeamHacker0);
152-
153- // chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify(hacker.toJSON()));
154-
155- // done();
156- // });
157- // });
158- // });
159-
160- // // fail due to lack of authorization
161- // it("should fail to list a hacker information due to lack of authorization on /api/hacker/:id GET", function (done) {
162- // util.auth.login(agent, noTeamHackerAccount0, (error) => {
163- // if (error) {
164- // agent.close();
165- // return done(error);
166- // }
167- // return agent
168- // .get(`/api/hacker/${TeamHacker0._id}`)
169- // // does not have password because of to stripped json
170- // .end(function (err, res) {
171- // if (err) {
172- // return done(err);
173- // }
174- // res.should.have.status(403);
175- // res.should.be.json;
176- // res.body.should.have.property("message");
177- // res.body.message.should.equal(Constants.Error.AUTH_403_MESSAGE);
178- // res.body.should.have.property("data");
179-
180- // done();
181- // });
182- // });
183- // });
184-
185- // // fail due to lack of hacker
186- // it("should fail to list an invalid hacker /api/hacker/:id GET", function (done) {
187- // util.auth.login(agent, Admin0, (error) => {
188- // if (error) {
189- // agent.close();
190- // return done(error);
191- // }
192- // return agent
193- // .get(`/api/hacker/${invalidHacker1._id}`)
194- // .end(function (err, res) {
195- // if (err) {
196- // return done(err);
197- // }
198- // res.should.have.status(404);
199- // res.should.be.json;
200- // res.body.should.have.property("message");
201- // res.body.message.should.equal(Constants.Error.HACKER_404_MESSAGE);
202- // res.body.should.have.property("data");
203-
204- // done();
205- // });
206- // });
207- // });
208- // });
44+ describe ( "GET hacker" , function ( ) {
45+ // fail on authentication
46+ it ( "should fail to list a hacker's information on /api/hacker/:id GET due to authentication" , function ( done ) {
47+ chai . request ( server . app )
48+ . get ( `/api/hacker/` + TeamHacker0 . _id )
49+ . end ( function ( err , res ) {
50+ res . should . have . status ( 401 ) ;
51+ res . should . be . json ;
52+ res . body . should . have . property ( "message" ) ;
53+ res . body . message . should . equal ( Constants . Error . AUTH_401_MESSAGE ) ;
54+ done ( ) ;
55+ } ) ;
56+ } ) ;
57+
58+ // success case
59+ it ( "should list the user's hacker info on /api/hacker/self GET" , function ( done ) {
60+ util . auth . login ( agent , teamHackerAccount0 , ( error ) => {
61+ if ( error ) {
62+ agent . close ( ) ;
63+ return done ( error ) ;
64+ }
65+ return agent
66+ . get ( "/api/hacker/self" )
67+ . end ( function ( err , res ) {
68+ if ( err ) {
69+ return done ( err ) ;
70+ }
71+ res . should . have . status ( 200 ) ;
72+ res . should . be . json ;
73+ res . body . should . have . property ( "message" ) ;
74+ res . body . message . should . equal ( Constants . Success . HACKER_READ ) ;
75+ res . body . should . have . property ( "data" ) ;
76+
77+ let hacker = new Hacker ( TeamHacker0 ) ;
78+ chai . assert . equal ( JSON . stringify ( res . body . data ) , JSON . stringify ( hacker . toJSON ( ) ) ) ;
79+ done ( ) ;
80+ } ) ;
81+ } ) ;
82+ } ) ;
83+
84+ // fail case due to wrong account type
85+ it ( "should fail to list the hacker info of an admin due to wrong account type /api/account/self GET" , function ( done ) {
86+ util . auth . login ( agent , Admin0 , ( error ) => {
87+ if ( error ) {
88+ agent . close ( ) ;
89+ return done ( error ) ;
90+ }
91+ return agent
92+ . get ( "/api/hacker/self" )
93+ . end ( function ( err , res ) {
94+ res . should . have . status ( 409 ) ;
95+ res . should . be . json ;
96+ res . body . should . have . property ( "message" ) ;
97+ res . body . message . should . equal ( Constants . Error . ACCOUNT_TYPE_409_MESSAGE ) ;
98+ done ( ) ;
99+ } ) ;
100+ } ) ;
101+ } ) ;
102+
103+ // succeed on admin case
104+ it ( "should list a hacker's information using admin power on /api/hacker/:id GET" , function ( done ) {
105+ util . auth . login ( agent , Admin0 , ( error ) => {
106+ if ( error ) {
107+ agent . close ( ) ;
108+ return done ( error ) ;
109+ }
110+ return agent
111+ . get ( `/api/hacker/${ TeamHacker0 . _id } ` )
112+ // does not have password because of to stripped json
113+ . end ( function ( err , res ) {
114+ if ( err ) {
115+ return done ( err ) ;
116+ }
117+ res . should . have . status ( 200 ) ;
118+ res . should . be . json ;
119+ res . body . should . have . property ( "message" ) ;
120+ res . body . message . should . equal ( Constants . Success . HACKER_READ ) ;
121+ res . body . should . have . property ( "data" ) ;
122+
123+ let hacker = new Hacker ( TeamHacker0 ) ;
124+ chai . assert . equal ( JSON . stringify ( res . body . data ) , JSON . stringify ( hacker . toJSON ( ) ) ) ;
125+
126+ done ( ) ;
127+ } ) ;
128+ } ) ;
129+ } ) ;
130+
131+ // succeed on :self case
132+ it ( "should list the user's hacker information on /api/hacker/:id GET" , function ( done ) {
133+ util . auth . login ( agent , teamHackerAccount0 , ( error ) => {
134+ if ( error ) {
135+ agent . close ( ) ;
136+ return done ( error ) ;
137+ }
138+ return agent
139+ . get ( `/api/hacker/${ TeamHacker0 . _id } ` )
140+ // does not have password because of to stripped json
141+ . end ( function ( err , res ) {
142+ if ( err ) {
143+ return done ( err ) ;
144+ }
145+ res . should . have . status ( 200 ) ;
146+ res . should . be . json ;
147+ res . body . should . have . property ( "message" ) ;
148+ res . body . message . should . equal ( Constants . Success . HACKER_READ ) ;
149+ res . body . should . have . property ( "data" ) ;
150+
151+ let hacker = new Hacker ( TeamHacker0 ) ;
152+
153+ chai . assert . equal ( JSON . stringify ( res . body . data ) , JSON . stringify ( hacker . toJSON ( ) ) ) ;
154+
155+ done ( ) ;
156+ } ) ;
157+ } ) ;
158+ } ) ;
159+
160+ // fail due to lack of authorization
161+ it ( "should fail to list a hacker information due to lack of authorization on /api/hacker/:id GET" , function ( done ) {
162+ util . auth . login ( agent , noTeamHackerAccount0 , ( error ) => {
163+ if ( error ) {
164+ agent . close ( ) ;
165+ return done ( error ) ;
166+ }
167+ return agent
168+ . get ( `/api/hacker/${ TeamHacker0 . _id } ` )
169+ // does not have password because of to stripped json
170+ . end ( function ( err , res ) {
171+ if ( err ) {
172+ return done ( err ) ;
173+ }
174+ res . should . have . status ( 403 ) ;
175+ res . should . be . json ;
176+ res . body . should . have . property ( "message" ) ;
177+ res . body . message . should . equal ( Constants . Error . AUTH_403_MESSAGE ) ;
178+ res . body . should . have . property ( "data" ) ;
179+
180+ done ( ) ;
181+ } ) ;
182+ } ) ;
183+ } ) ;
184+
185+ // fail due to lack of hacker
186+ it ( "should fail to list an invalid hacker /api/hacker/:id GET" , function ( done ) {
187+ util . auth . login ( agent , Admin0 , ( error ) => {
188+ if ( error ) {
189+ agent . close ( ) ;
190+ return done ( error ) ;
191+ }
192+ return agent
193+ . get ( `/api/hacker/${ invalidHacker1 . _id } ` )
194+ . end ( function ( err , res ) {
195+ if ( err ) {
196+ return done ( err ) ;
197+ }
198+ res . should . have . status ( 404 ) ;
199+ res . should . be . json ;
200+ res . body . should . have . property ( "message" ) ;
201+ res . body . message . should . equal ( Constants . Error . HACKER_404_MESSAGE ) ;
202+ res . body . should . have . property ( "data" ) ;
203+
204+ done ( ) ;
205+ } ) ;
206+ } ) ;
207+ } ) ;
208+ } ) ;
209209
210210describe ( "POST create hacker" , function ( ) {
211211 // fail on authentication
0 commit comments