Skip to content

Commit

Permalink
fix(test): vendor controller
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnan05 committed Apr 2, 2024
1 parent 3e7d484 commit 74f13d6
Show file tree
Hide file tree
Showing 22 changed files with 449 additions and 598 deletions.
2 changes: 1 addition & 1 deletion __tests__/controllers/vendorController/addItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("POST /api/v1/vendor/menuitems", () => {
is_healthy: false,
on_offer: false,
offer_price: 49,
}).expect(400);
}).expect(401);
// .expect(201);
});
}, 100000);
2 changes: 1 addition & 1 deletion __tests__/controllers/vendorController/updateItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("PUT /api/v1/vendor/menuitems", () => {
on_offer: false,
offer_price: 49,
})
.expect(404);
.expect(401);
// expect(res.body).toHaveProperty("name");
// expect(res.body).toHaveProperty("price");

Expand Down
238 changes: 97 additions & 141 deletions coverage/clover.xml

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions coverage/coverage-final.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions coverage/lcov-report/Inventory-Service/config/dbConnection.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se
<div class='clearfix'>

<div class='fl pad1y space-right2'>
<span class="strong">81.25% </span>
<span class="strong">56.25% </span>
<span class="quiet">Statements</span>
<span class='fraction'>13/16</span>
<span class='fraction'>9/16</span>
</div>


<div class='fl pad1y space-right2'>
<span class="strong">66.66% </span>
<span class="strong">50% </span>
<span class="quiet">Branches</span>
<span class='fraction'>2/3</span>
<span class='fraction'>1/2</span>
</div>


Expand All @@ -44,9 +44,9 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se


<div class='fl pad1y space-right2'>
<span class="strong">81.25% </span>
<span class="strong">56.25% </span>
<span class="quiet">Lines</span>
<span class='fraction'>13/16</span>
<span class='fraction'>9/16</span>
</div>


Expand All @@ -61,7 +61,7 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se
</div>
</template>
</div>
<div class='status-line high'></div>
<div class='status-line medium'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
<a name='L2'></a><a href='#L2'>2</a>
Expand All @@ -81,28 +81,28 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se
<a name='L16'></a><a href='#L16'>16</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">5x</span>
<span class="cline-any cline-yes">5x</span>
<span class="cline-any cline-yes">5x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">5x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span></td><td class="text"><pre class="prettyprint lang-js">const mongoose = require('mongoose');
&nbsp;
const connectDb = async ()=&gt;{
try{

const connect = await mongoose.connect( process.env.CONNECTION_STRING);
console.log('Connected to database', connect.connection.host, connect.connection.name);
&nbsp;
}
<span class="branch-0 cbranch-no" title="branch not covered" > catch(err){</span>
const connect = await mongoose.connect( process.env.CONNECTION_STRING)<span class="branch-0 cbranch-no" title="branch not covered" >;</span>
<span class="cstat-no" title="statement not covered" > console.log('Connected to database', connect.connection.host, connect.connection.name);</span>
<span class="cstat-no" title="statement not covered" ></span>
<span class="cstat-no" title="statement not covered" > }</span>
<span class="cstat-no" title="statement not covered" > catch(err){</span>
<span class="cstat-no" title="statement not covered" > console.error(err);</span>
<span class="cstat-no" title="statement not covered" > process.exit(1);</span>
<span class="cstat-no" title="statement not covered" > }</span>
Expand All @@ -115,7 +115,7 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se
<div class='footer quiet pad2 space-top1 center small'>
Code coverage generated by
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
at 2024-04-02T18:31:32.837Z
at 2024-04-02T18:55:05.410Z
</div>
<script src="../../prettify.js"></script>
<script>
Expand Down
34 changes: 17 additions & 17 deletions coverage/lcov-report/Inventory-Service/config/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ <h1><a href="../../index.html">All files</a> Inventory-Service/config</h1>
<div class='clearfix'>

<div class='fl pad1y space-right2'>
<span class="strong">81.25% </span>
<span class="strong">56.25% </span>
<span class="quiet">Statements</span>
<span class='fraction'>13/16</span>
<span class='fraction'>9/16</span>
</div>


<div class='fl pad1y space-right2'>
<span class="strong">66.66% </span>
<span class="strong">50% </span>
<span class="quiet">Branches</span>
<span class='fraction'>2/3</span>
<span class='fraction'>1/2</span>
</div>


Expand All @@ -44,9 +44,9 @@ <h1><a href="../../index.html">All files</a> Inventory-Service/config</h1>


<div class='fl pad1y space-right2'>
<span class="strong">81.25% </span>
<span class="strong">56.25% </span>
<span class="quiet">Lines</span>
<span class='fraction'>13/16</span>
<span class='fraction'>9/16</span>
</div>


Expand All @@ -61,7 +61,7 @@ <h1><a href="../../index.html">All files</a> Inventory-Service/config</h1>
</div>
</template>
</div>
<div class='status-line high'></div>
<div class='status-line medium'></div>
<div class="pad1">
<table class="coverage-summary">
<thead>
Expand All @@ -79,18 +79,18 @@ <h1><a href="../../index.html">All files</a> Inventory-Service/config</h1>
</tr>
</thead>
<tbody><tr>
<td class="file high" data-value="dbConnection.js"><a href="dbConnection.js.html">dbConnection.js</a></td>
<td data-value="81.25" class="pic high">
<div class="chart"><div class="cover-fill" style="width: 81%"></div><div class="cover-empty" style="width: 19%"></div></div>
<td class="file medium" data-value="dbConnection.js"><a href="dbConnection.js.html">dbConnection.js</a></td>
<td data-value="56.25" class="pic medium">
<div class="chart"><div class="cover-fill" style="width: 56%"></div><div class="cover-empty" style="width: 44%"></div></div>
</td>
<td data-value="81.25" class="pct high">81.25%</td>
<td data-value="16" class="abs high">13/16</td>
<td data-value="66.66" class="pct medium">66.66%</td>
<td data-value="3" class="abs medium">2/3</td>
<td data-value="56.25" class="pct medium">56.25%</td>
<td data-value="16" class="abs medium">9/16</td>
<td data-value="50" class="pct medium">50%</td>
<td data-value="2" class="abs medium">1/2</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="1" class="abs high">1/1</td>
<td data-value="81.25" class="pct high">81.25%</td>
<td data-value="16" class="abs high">13/16</td>
<td data-value="56.25" class="pct medium">56.25%</td>
<td data-value="16" class="abs medium">9/16</td>
</tr>

</tbody>
Expand All @@ -101,7 +101,7 @@ <h1><a href="../../index.html">All files</a> Inventory-Service/config</h1>
<div class='footer quiet pad2 space-top1 center small'>
Code coverage generated by
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
at 2024-04-02T18:31:32.837Z
at 2024-04-02T18:55:05.410Z
</div>
<script src="../../prettify.js"></script>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se
<div class='clearfix'>

<div class='fl pad1y space-right2'>
<span class="strong">46.75% </span>
<span class="strong">31.81% </span>
<span class="quiet">Statements</span>
<span class='fraction'>72/154</span>
<span class='fraction'>49/154</span>
</div>


<div class='fl pad1y space-right2'>
<span class="strong">16.66% </span>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>1/6</span>
<span class='fraction'>0/0</span>
</div>


Expand All @@ -44,9 +44,9 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se


<div class='fl pad1y space-right2'>
<span class="strong">46.75% </span>
<span class="strong">31.81% </span>
<span class="quiet">Lines</span>
<span class='fraction'>72/154</span>
<span class='fraction'>49/154</span>
</div>


Expand Down Expand Up @@ -228,42 +228,42 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
Expand Down Expand Up @@ -382,42 +382,42 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se
//@access public
&nbsp;
exports.getVendors = asyncHandler(async (req, res) =&gt; {
try {
const {
primary_location,
tag,
is_veg,
sort,
page = 1,
pageSize = 10,
} = req.query;
const filters = {};
if (primary_location) <span class="branch-0 cbranch-no" title="branch not covered" >{</span>
<span class="cstat-no" title="statement not covered" > try {</span>
<span class="cstat-no" title="statement not covered" > const {</span>
<span class="cstat-no" title="statement not covered" > primary_location,</span>
<span class="cstat-no" title="statement not covered" > tag,</span>
<span class="cstat-no" title="statement not covered" > is_veg,</span>
<span class="cstat-no" title="statement not covered" > sort,</span>
<span class="cstat-no" title="statement not covered" > page = 1,</span>
<span class="cstat-no" title="statement not covered" > pageSize = 10,</span>
<span class="cstat-no" title="statement not covered" > } = req.query;</span>
<span class="cstat-no" title="statement not covered" > const filters = {};</span>
<span class="cstat-no" title="statement not covered" > if (primary_location) {</span>
<span class="cstat-no" title="statement not covered" > filters.location_served = { $in: [primary_location] };</span>
<span class="cstat-no" title="statement not covered" > }</span>
if (tag) <span class="branch-0 cbranch-no" title="branch not covered" >{</span>
<span class="cstat-no" title="statement not covered" > if (tag) {</span>
<span class="cstat-no" title="statement not covered" > filters.tags = { $in: [tag] };</span>
<span class="cstat-no" title="statement not covered" > }</span>
if (is_veg) <span class="branch-0 cbranch-no" title="branch not covered" >{</span>
<span class="cstat-no" title="statement not covered" > if (is_veg) {</span>
<span class="cstat-no" title="statement not covered" > filters.is_veg = true;</span>
<span class="cstat-no" title="statement not covered" > }</span>
&nbsp;
const sortOptions = {};
if (sort) <span class="branch-0 cbranch-no" title="branch not covered" >{</span>
<span class="cstat-no" title="statement not covered" ></span>
<span class="cstat-no" title="statement not covered" > const sortOptions = {};</span>
<span class="cstat-no" title="statement not covered" > if (sort) {</span>
<span class="cstat-no" title="statement not covered" > const sortFields = sort.split(",");</span>
<span class="cstat-no" title="statement not covered" > sortFields.forEach((field) =&gt; {</span>
<span class="cstat-no" title="statement not covered" > const order = field.endsWith("-") ? -1 : 1;</span>
<span class="cstat-no" title="statement not covered" > const fieldName = field.replace(/[+-]/g, "");</span>
<span class="cstat-no" title="statement not covered" > sortOptions[fieldName] = order;</span>
<span class="cstat-no" title="statement not covered" > });</span>
<span class="cstat-no" title="statement not covered" > }</span>
&nbsp;
const vendors = await Vendor.find(filters)
.sort(sortOptions)
.skip((page - 1) * pageSize)
.limit(pageSize);
return res.status(200).json(vendors);
} <span class="branch-0 cbranch-no" title="branch not covered" >catch (err) {</span>
<span class="cstat-no" title="statement not covered" ></span>
<span class="cstat-no" title="statement not covered" > const vendors = await Vendor.find(filters)</span>
<span class="cstat-no" title="statement not covered" > .sort(sortOptions)</span>
<span class="cstat-no" title="statement not covered" > .skip((page - 1) * pageSize)</span>
<span class="cstat-no" title="statement not covered" > .limit(pageSize);</span>
<span class="cstat-no" title="statement not covered" > return res.status(200).json(vendors);</span>
<span class="cstat-no" title="statement not covered" > } catch (err) {</span>
<span class="cstat-no" title="statement not covered" > return res.status(500).json({ error: "Internal Server Error" });</span>
<span class="cstat-no" title="statement not covered" > }</span>
});
Expand Down Expand Up @@ -532,7 +532,7 @@ <h1><a href="../../index.html">All files</a> / <a href="index.html">Inventory-Se
<div class='footer quiet pad2 space-top1 center small'>
Code coverage generated by
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
at 2024-04-02T18:31:32.837Z
at 2024-04-02T18:55:05.410Z
</div>
<script src="../../prettify.js"></script>
<script>
Expand Down
Loading

0 comments on commit 74f13d6

Please sign in to comment.