1+ let mongoose = require ( "mongoose" ) ;
2+ let server = require ( "./app" ) ;
3+ let chai = require ( "chai" ) ;
4+ let chaiHttp = require ( "chai-http" ) ;
5+
6+
7+ // Assertion
8+ chai . should ( ) ;
9+ chai . use ( chaiHttp ) ;
10+
11+ describe ( 'Planets API Suite' , ( ) => {
12+
13+ describe ( 'Fetching Planet Details' , ( ) => {
14+ it ( 'it should fetch a planet named Mercury' , ( done ) => {
15+ let payload = {
16+ id : 1
17+ }
18+ chai . request ( server )
19+ . post ( '/planet' )
20+ . send ( payload )
21+ . end ( ( err , res ) => {
22+ res . should . have . status ( 200 ) ;
23+ res . body . should . have . property ( 'id' ) . eql ( 1 ) ;
24+ res . body . should . have . property ( 'name' ) . eql ( 'Mercury' ) ;
25+ done ( ) ;
26+ } ) ;
27+ } ) ;
28+
29+ it ( 'it should fetch a planet named Venus' , ( done ) => {
30+ let payload = {
31+ id : 2
32+ }
33+ chai . request ( server )
34+ . post ( '/planet' )
35+ . send ( payload )
36+ . end ( ( err , res ) => {
37+ res . should . have . status ( 200 ) ;
38+ res . body . should . have . property ( 'id' ) . eql ( 2 ) ;
39+ res . body . should . have . property ( 'name' ) . eql ( 'Venus' ) ;
40+ done ( ) ;
41+ } ) ;
42+ } ) ;
43+
44+ it ( 'it should fetch a planet named Earth' , ( done ) => {
45+ let payload = {
46+ id : 3
47+ }
48+ chai . request ( server )
49+ . post ( '/planet' )
50+ . send ( payload )
51+ . end ( ( err , res ) => {
52+ res . should . have . status ( 200 ) ;
53+ res . body . should . have . property ( 'id' ) . eql ( 3 ) ;
54+ res . body . should . have . property ( 'name' ) . eql ( 'Earth' ) ;
55+ done ( ) ;
56+ } ) ;
57+ } ) ;
58+ it ( 'it should fetch a planet named Mars' , ( done ) => {
59+ let payload = {
60+ id : 4
61+ }
62+ chai . request ( server )
63+ . post ( '/planet' )
64+ . send ( payload )
65+ . end ( ( err , res ) => {
66+ res . should . have . status ( 200 ) ;
67+ res . body . should . have . property ( 'id' ) . eql ( 4 ) ;
68+ res . body . should . have . property ( 'name' ) . eql ( 'Mars' ) ;
69+ done ( ) ;
70+ } ) ;
71+ } ) ;
72+
73+ it ( 'it should fetch a planet named Jupiter' , ( done ) => {
74+ let payload = {
75+ id : 5
76+ }
77+ chai . request ( server )
78+ . post ( '/planet' )
79+ . send ( payload )
80+ . end ( ( err , res ) => {
81+ res . should . have . status ( 200 ) ;
82+ res . body . should . have . property ( 'id' ) . eql ( 5 ) ;
83+ res . body . should . have . property ( 'name' ) . eql ( 'Jupiter' ) ;
84+ done ( ) ;
85+ } ) ;
86+ } ) ;
87+
88+ it ( 'it should fetch a planet named Satrun' , ( done ) => {
89+ let payload = {
90+ id : 6
91+ }
92+ chai . request ( server )
93+ . post ( '/planet' )
94+ . send ( payload )
95+ . end ( ( err , res ) => {
96+ res . should . have . status ( 200 ) ;
97+ res . body . should . have . property ( 'id' ) . eql ( 6 ) ;
98+ res . body . should . have . property ( 'name' ) . eql ( 'Saturn' ) ;
99+ done ( ) ;
100+ } ) ;
101+ } ) ;
102+
103+ it ( 'it should fetch a planet named Uranus' , ( done ) => {
104+ let payload = {
105+ id : 7
106+ }
107+ chai . request ( server )
108+ . post ( '/planet' )
109+ . send ( payload )
110+ . end ( ( err , res ) => {
111+ res . should . have . status ( 200 ) ;
112+ res . body . should . have . property ( 'id' ) . eql ( 7 ) ;
113+ res . body . should . have . property ( 'name' ) . eql ( 'Uranus' ) ;
114+ done ( ) ;
115+ } ) ;
116+ } ) ;
117+
118+ it ( 'it should fetch a planet named Neptune' , ( done ) => {
119+ let payload = {
120+ id : 8
121+ }
122+ chai . request ( server )
123+ . post ( '/planet' )
124+ . send ( payload )
125+ . end ( ( err , res ) => {
126+ res . should . have . status ( 200 ) ;
127+ res . body . should . have . property ( 'id' ) . eql ( 8 ) ;
128+ res . body . should . have . property ( 'name' ) . eql ( 'Neptune' ) ;
129+ done ( ) ;
130+ } ) ;
131+ } ) ;
132+
133+ // it('it should fetch a planet named Pluto', (done) => {
134+ // let payload = {
135+ // id: 9
136+ // }
137+ // chai.request(server)
138+ // .post('/planet')
139+ // .send(payload)
140+ // .end((err, res) => {
141+ // res.should.have.status(200);
142+ // res.body.should.have.property('id').eql(9);
143+ // res.body.should.have.property('name').eql('Sun');
144+ // done();
145+ // });
146+ // });
147+
148+
149+ } ) ;
150+ } ) ;
151+
152+ //Use below test case to achieve coverage
153+ describe ( 'Testing Other Endpoints' , ( ) => {
154+
155+ describe ( 'it should fetch OS Details' , ( ) => {
156+ it ( 'it should fetch OS details' , ( done ) => {
157+ chai . request ( server )
158+ . get ( '/os' )
159+ . end ( ( err , res ) => {
160+ res . should . have . status ( 200 ) ;
161+ done ( ) ;
162+ } ) ;
163+ } ) ;
164+ } ) ;
165+
166+ describe ( 'it should fetch Live Status' , ( ) => {
167+ it ( 'it checks Liveness endpoint' , ( done ) => {
168+ chai . request ( server )
169+ . get ( '/live' )
170+ . end ( ( err , res ) => {
171+ res . should . have . status ( 200 ) ;
172+ res . body . should . have . property ( 'status' ) . eql ( 'live' ) ;
173+ done ( ) ;
174+ } ) ;
175+ } ) ;
176+ } ) ;
177+
178+ describe ( 'it should fetch Ready Status' , ( ) => {
179+ it ( 'it checks Readiness endpoint' , ( done ) => {
180+ chai . request ( server )
181+ . get ( '/ready' )
182+ . end ( ( err , res ) => {
183+ res . should . have . status ( 200 ) ;
184+ res . body . should . have . property ( 'status' ) . eql ( 'ready' ) ;
185+ done ( ) ;
186+ } ) ;
187+ } ) ;
188+ } ) ;
189+
190+ } ) ;
0 commit comments