Conditions | 1 |
Paths | 1 |
Total Lines | 140 |
Code Lines | 90 |
Lines | 140 |
Ratio | 100 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* global it describe before */ |
||
20 | describe('copier', () => { |
||
21 | before(() => { |
||
22 | return new Promise((resolve) => { |
||
23 | db.run("DELETE FROM products", (err) => { |
||
24 | if (err) { |
||
25 | console.error("Could not empty test DB table orders", err.message); |
||
26 | } |
||
27 | |||
28 | db.run("DELETE FROM orders", (err) => { |
||
29 | if (err) { |
||
30 | console.error("Could not empty test DB table orders", err.message); |
||
31 | } |
||
32 | |||
33 | db.run("DELETE FROM order_items", (err) => { |
||
34 | if (err) { |
||
35 | console.error("Could not empty test DB table orders", err.message); |
||
36 | } |
||
37 | |||
38 | exec( |
||
39 | 'cat v2/db/seed.sql | sqlite3 v2/db/test.sqlite', |
||
40 | (error, stdout, stderr) => { |
||
41 | if (error) { |
||
42 | console.error(error.message); |
||
43 | return; |
||
44 | } |
||
45 | |||
46 | if (stderr) { |
||
47 | console.error(stderr); |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | resolve(); |
||
52 | }); |
||
53 | }); |
||
54 | }); |
||
55 | }); |
||
56 | }); |
||
57 | }); |
||
58 | |||
59 | describe('POST /copier/products', () => { |
||
60 | it('should get 401 as we do not provide valid api_key', (done) => { |
||
61 | chai.request(server) |
||
62 | .post("/v2/copier/products") |
||
63 | .end((err, res) => { |
||
64 | res.should.have.status(401); |
||
65 | res.body.should.be.an("object"); |
||
66 | res.body.errors.status.should.be.equal(401); |
||
67 | |||
68 | done(); |
||
69 | }); |
||
70 | }); |
||
71 | |||
72 | it('should get 200 HAPPY PATH FROM GETTING API KEY', (done) => { |
||
73 | chai.request(server) |
||
74 | .get("/v2/auth/[email protected]") |
||
75 | .end((err, res) => { |
||
76 | res.should.have.status(200); |
||
77 | res.body.should.be.an("object"); |
||
78 | res.body.data.should.be.an("object"); |
||
79 | res.body.data.should.have.property("key"); |
||
80 | |||
81 | apiKey = res.body.data.key; |
||
82 | |||
83 | done(); |
||
84 | }); |
||
85 | }); |
||
86 | |||
87 | it('should get 201 HAPPY PATH, 10 products should have been created', (done) => { |
||
88 | chai.request(server) |
||
89 | .post("/v2/copier/products") |
||
90 | .send({ api_key: apiKey }) |
||
91 | .end((err, res) => { |
||
92 | res.should.have.status(201); |
||
93 | res.body.should.be.an("object"); |
||
94 | res.body.data.should.be.an("array"); |
||
95 | res.body.data.length.should.equal(10); |
||
96 | |||
97 | done(); |
||
98 | }); |
||
99 | }); |
||
100 | }); |
||
101 | |||
102 | describe('POST /copy_orders', () => { |
||
103 | it('should get 201 HAPPY PATH, 4 orders should have been created', (done) => { |
||
104 | chai.request(server) |
||
105 | .post("/v2/copier/orders") |
||
106 | .send({ api_key: apiKey }) |
||
107 | .end((err, res) => { |
||
108 | res.should.have.status(201); |
||
109 | res.body.should.be.an("object"); |
||
110 | res.body.data.should.be.an("array"); |
||
111 | res.body.data.length.should.equal(4); |
||
112 | |||
113 | done(); |
||
114 | }); |
||
115 | }); |
||
116 | }); |
||
117 | |||
118 | describe("POST /copy_all", () => { |
||
119 | it('should get 401 as we do not provide valid api_key', (done) => { |
||
120 | chai.request(server) |
||
121 | .post("/v2/copier/all") |
||
122 | .end((err, res) => { |
||
123 | res.should.have.status(401); |
||
124 | res.body.should.be.an("object"); |
||
125 | res.body.errors.status.should.be.equal(401); |
||
126 | |||
127 | done(); |
||
128 | }); |
||
129 | }); |
||
130 | |||
131 | it('should get 200 HAPPY PATH FROM GETTING API KEY', (done) => { |
||
132 | chai.request(server) |
||
133 | .get("/v2/auth/[email protected]") |
||
134 | .end((err, res) => { |
||
135 | res.should.have.status(200); |
||
136 | res.body.should.be.an("object"); |
||
137 | res.body.data.should.be.an("object"); |
||
138 | res.body.data.should.have.property("key"); |
||
139 | |||
140 | apiKey = res.body.data.key; |
||
141 | |||
142 | done(); |
||
143 | }); |
||
144 | }); |
||
145 | |||
146 | it('should get 201 HAPPY PATH', (done) => { |
||
147 | chai.request(server) |
||
148 | .post("/v2/copier/all") |
||
149 | .send({ api_key: apiKey }) |
||
150 | .end((err, res) => { |
||
151 | res.should.have.status(201); |
||
152 | res.body.should.be.an("object"); |
||
153 | res.body.data.should.have.property("message"); |
||
154 | |||
155 | done(); |
||
156 | }); |
||
157 | }); |
||
158 | }); |
||
159 | }); |
||
160 |