mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-17 19:37:02 +00:00
chore: adding user creation tests
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
},
|
||||
"plugins": ["@typescript-eslint", "prettier"],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{ "argsIgnorePattern": "_" }
|
||||
|
||||
@@ -187,7 +187,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -214,7 +214,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -274,7 +274,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -187,7 +187,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -250,7 +250,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -184,7 +184,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -496,7 +496,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -154,7 +154,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -250,7 +250,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -199,7 +199,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -23,30 +23,30 @@
|
||||
<div class='clearfix'>
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>0/70</span>
|
||||
<span class='fraction'>67/67</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">71.88% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>0/1</span>
|
||||
<span class='fraction'>23/32</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">90% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>0/1</span>
|
||||
<span class='fraction'>9/10</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>0/70</span>
|
||||
<span class='fraction'>67/67</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
</div>
|
||||
<div class='status-line low'></div>
|
||||
<div class='status-line high'></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>
|
||||
@@ -124,149 +124,140 @@
|
||||
<a name='L65'></a><a href='#L65'>65</a>
|
||||
<a name='L66'></a><a href='#L66'>66</a>
|
||||
<a name='L67'></a><a href='#L67'>67</a>
|
||||
<a name='L68'></a><a href='#L68'>68</a>
|
||||
<a name='L69'></a><a href='#L69'>69</a>
|
||||
<a name='L70'></a><a href='#L70'>70</a>
|
||||
<a name='L71'></a><a href='#L71'>71</a></td><td class="line-coverage quiet"><span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js"><span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" ><span class="branch-0 cbranch-no" title="branch not covered" >import * as Yup from "yup";</span></span></span>
|
||||
<span class="cstat-no" title="statement not covered" ></span>
|
||||
<span class="cstat-no" title="statement not covered" >import AppError from "../../errors/AppError";</span>
|
||||
<span class="cstat-no" title="statement not covered" >import User from "../../models/User";</span>
|
||||
<span class="cstat-no" title="statement not covered" ></span>
|
||||
<span class="cstat-no" title="statement not covered" >interface Request {</span>
|
||||
<span class="cstat-no" title="statement not covered" > email: string;</span>
|
||||
<span class="cstat-no" title="statement not covered" > password: string;</span>
|
||||
<span class="cstat-no" title="statement not covered" > name: string;</span>
|
||||
<span class="cstat-no" title="statement not covered" > profile?: string;</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" >interface Response {</span>
|
||||
<span class="cstat-no" title="statement not covered" > email: string;</span>
|
||||
<span class="cstat-no" title="statement not covered" > name: string;</span>
|
||||
<span class="cstat-no" title="statement not covered" > id: number;</span>
|
||||
<span class="cstat-no" title="statement not covered" > profile: string;</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" >const CreateUserService = async ({</span>
|
||||
<span class="cstat-no" title="statement not covered" > email,</span>
|
||||
<span class="cstat-no" title="statement not covered" > password,</span>
|
||||
<span class="cstat-no" title="statement not covered" > name,</span>
|
||||
<span class="cstat-no" title="statement not covered" > profile = "admin"</span>
|
||||
<span class="cstat-no" title="statement not covered" >}: Request): Promise<Response> => {</span>
|
||||
<span class="cstat-no" title="statement not covered" > const schema = Yup.object().shape({</span>
|
||||
<span class="cstat-no" title="statement not covered" > name: Yup.string().required().min(2),</span>
|
||||
<span class="cstat-no" title="statement not covered" > email: Yup.string()</span>
|
||||
<span class="cstat-no" title="statement not covered" > .email()</span>
|
||||
<span class="cstat-no" title="statement not covered" > .required()</span>
|
||||
<span class="cstat-no" title="statement not covered" > .test(</span>
|
||||
<span class="cstat-no" title="statement not covered" > "Check-email",</span>
|
||||
<span class="cstat-no" title="statement not covered" > "An user with this email already exists.",</span>
|
||||
<span class="cstat-no" title="statement not covered" > async value => {</span>
|
||||
<span class="cstat-no" title="statement not covered" > if (value) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > const emailExists = await User.findOne({</span>
|
||||
<span class="cstat-no" title="statement not covered" > where: { email: value }</span>
|
||||
<span class="cstat-no" title="statement not covered" > });</span>
|
||||
<span class="cstat-no" title="statement not covered" > return !emailExists;</span>
|
||||
<span class="cstat-no" title="statement not covered" > }</span>
|
||||
<span class="cstat-no" title="statement not covered" > return false;</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" > password: Yup.string().required().min(5)</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" > try {</span>
|
||||
<span class="cstat-no" title="statement not covered" > await schema.validate({ email, password, name });</span>
|
||||
<span class="cstat-no" title="statement not covered" > } catch (err) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > throw new AppError(err.message);</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" > const user = await User.create({</span>
|
||||
<span class="cstat-no" title="statement not covered" > email,</span>
|
||||
<span class="cstat-no" title="statement not covered" > password,</span>
|
||||
<span class="cstat-no" title="statement not covered" > name,</span>
|
||||
<span class="cstat-no" title="statement not covered" > profile</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" > const serializedUser = {</span>
|
||||
<span class="cstat-no" title="statement not covered" > id: user.id,</span>
|
||||
<span class="cstat-no" title="statement not covered" > name: user.name,</span>
|
||||
<span class="cstat-no" title="statement not covered" > email: user.email,</span>
|
||||
<span class="cstat-no" title="statement not covered" > profile: user.profile</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" > return serializedUser;</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" >export default CreateUserService;</span>
|
||||
<a name='L68'></a><a href='#L68'>68</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">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-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">5x</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">5x</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">5x</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">5x</span>
|
||||
<span class="cline-any cline-yes">5x</span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-yes">4x</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">5x</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">1x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import * as Yup from "yup";
|
||||
|
||||
import AppError from "../../errors/AppError";
|
||||
import User from "../../models/User";
|
||||
|
||||
interface Request {
|
||||
email: string;
|
||||
password: string;
|
||||
name: string;
|
||||
profile?: string;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
email: string;
|
||||
name: string;
|
||||
id: number;
|
||||
profile: string;
|
||||
}
|
||||
|
||||
const CreateUserService = async ({
|
||||
email,
|
||||
password,
|
||||
name,
|
||||
profile = "admin"
|
||||
}: Request): Promise<Response> => {
|
||||
const schema = Yup.object().shape({
|
||||
name: Yup.string().required().min(2),
|
||||
email: Yup.string()
|
||||
.email()
|
||||
.required()
|
||||
.test(
|
||||
"Check-email",
|
||||
"An user with this email already exists.",
|
||||
async value => {
|
||||
const emailExists = await User.findOne({
|
||||
where: { email: value! }
|
||||
});
|
||||
return !emailExists;
|
||||
}
|
||||
),
|
||||
password: Yup.string().required().min(5)
|
||||
});
|
||||
|
||||
try {
|
||||
await schema.validate({ email, password, name });
|
||||
} catch (err) {
|
||||
throw new AppError(err.message);
|
||||
}
|
||||
|
||||
const user = await User.create({
|
||||
email,
|
||||
password,
|
||||
name,
|
||||
profile
|
||||
});
|
||||
|
||||
const serializedUser = {
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
profile: user.profile
|
||||
};
|
||||
|
||||
return serializedUser;
|
||||
};
|
||||
|
||||
export default CreateUserService;<span class="fstat-no" title="function not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ></span></span></span></span></span></span></span></span></span></span>
|
||||
</pre></td></tr></table></pre>
|
||||
|
||||
<div class='push'></div><!-- for sticky footer -->
|
||||
@@ -274,7 +265,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -217,7 +217,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -268,7 +268,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -23,30 +23,30 @@
|
||||
<div class='clearfix'>
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">24.54% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>0/276</span>
|
||||
<span class='fraction'>67/273</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">62.16% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>0/6</span>
|
||||
<span class='fraction'>23/37</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">60% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>0/6</span>
|
||||
<span class='fraction'>9/15</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">24.54% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>0/276</span>
|
||||
<span class='fraction'>67/273</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -88,18 +88,18 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="file low" data-value="CreateUserService.ts"><a href="CreateUserService.ts.html">CreateUserService.ts</a></td>
|
||||
<td data-value="0" class="pic low">
|
||||
<div class="chart"><div class="cover-fill" style="width: 0%"></div><div class="cover-empty" style="width: 100%"></div></div>
|
||||
<td class="file high" data-value="CreateUserService.ts"><a href="CreateUserService.ts.html">CreateUserService.ts</a></td>
|
||||
<td data-value="100" class="pic high">
|
||||
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
|
||||
</td>
|
||||
<td data-value="0" class="pct low">0%</td>
|
||||
<td data-value="70" class="abs low">0/70</td>
|
||||
<td data-value="0" class="pct low">0%</td>
|
||||
<td data-value="1" class="abs low">0/1</td>
|
||||
<td data-value="0" class="pct low">0%</td>
|
||||
<td data-value="1" class="abs low">0/1</td>
|
||||
<td data-value="0" class="pct low">0%</td>
|
||||
<td data-value="70" class="abs low">0/70</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="67" class="abs high">67/67</td>
|
||||
<td data-value="71.88" class="pct medium">71.88%</td>
|
||||
<td data-value="32" class="abs medium">23/32</td>
|
||||
<td data-value="90" class="pct high">90%</td>
|
||||
<td data-value="10" class="abs high">9/10</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="67" class="abs high">67/67</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
@@ -170,7 +170,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -172,7 +172,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -157,7 +157,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -215,7 +215,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -1063,7 +1063,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -325,7 +325,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -262,7 +262,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -262,7 +262,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../prettify.js"></script>
|
||||
|
||||
@@ -23,30 +23,30 @@
|
||||
<div class='clearfix'>
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">3.85% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>0/1742</span>
|
||||
<span class='fraction'>67/1739</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">34.85% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>0/35</span>
|
||||
<span class='fraction'>23/66</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">20.45% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>0/35</span>
|
||||
<span class='fraction'>9/44</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">0% </span>
|
||||
<span class="strong">3.85% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>0/1742</span>
|
||||
<span class='fraction'>67/1739</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -149,17 +149,17 @@
|
||||
|
||||
<tr>
|
||||
<td class="file low" data-value="UserServices"><a href="UserServices/index.html">UserServices</a></td>
|
||||
<td data-value="0" class="pic low">
|
||||
<div class="chart"><div class="cover-fill" style="width: 0%"></div><div class="cover-empty" style="width: 100%"></div></div>
|
||||
<td data-value="24.54" class="pic low">
|
||||
<div class="chart"><div class="cover-fill" style="width: 24%"></div><div class="cover-empty" style="width: 76%"></div></div>
|
||||
</td>
|
||||
<td data-value="0" class="pct low">0%</td>
|
||||
<td data-value="276" class="abs low">0/276</td>
|
||||
<td data-value="0" class="pct low">0%</td>
|
||||
<td data-value="6" class="abs low">0/6</td>
|
||||
<td data-value="0" class="pct low">0%</td>
|
||||
<td data-value="6" class="abs low">0/6</td>
|
||||
<td data-value="0" class="pct low">0%</td>
|
||||
<td data-value="276" class="abs low">0/276</td>
|
||||
<td data-value="24.54" class="pct low">24.54%</td>
|
||||
<td data-value="273" class="abs low">67/273</td>
|
||||
<td data-value="62.16" class="pct medium">62.16%</td>
|
||||
<td data-value="37" class="abs medium">23/37</td>
|
||||
<td data-value="60" class="pct medium">60%</td>
|
||||
<td data-value="15" class="abs medium">9/15</td>
|
||||
<td data-value="24.54" class="pct low">24.54%</td>
|
||||
<td data-value="273" class="abs low">67/273</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
@@ -200,7 +200,7 @@
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
||||
at Thu Oct 22 2020 13:34:21 GMT-0300 (Brasilia Standard Time)
|
||||
at Fri Oct 23 2020 11:53:22 GMT-0300 (Brasilia Standard Time)
|
||||
</div>
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
|
||||
@@ -906,85 +906,131 @@ BRH:0
|
||||
end_of_record
|
||||
TN:
|
||||
SF:src/services/UserServices/CreateUserService.ts
|
||||
FN:1,(empty-report)
|
||||
FNF:1
|
||||
FNH:0
|
||||
FNDA:0,(empty-report)
|
||||
DA:1,0
|
||||
DA:2,0
|
||||
DA:3,0
|
||||
DA:4,0
|
||||
DA:5,0
|
||||
DA:6,0
|
||||
DA:7,0
|
||||
DA:8,0
|
||||
DA:9,0
|
||||
DA:10,0
|
||||
DA:11,0
|
||||
DA:12,0
|
||||
DA:13,0
|
||||
DA:14,0
|
||||
DA:15,0
|
||||
DA:16,0
|
||||
DA:17,0
|
||||
DA:18,0
|
||||
DA:19,0
|
||||
DA:20,0
|
||||
DA:21,0
|
||||
DA:22,0
|
||||
DA:23,0
|
||||
DA:24,0
|
||||
DA:25,0
|
||||
DA:26,0
|
||||
DA:27,0
|
||||
DA:28,0
|
||||
DA:29,0
|
||||
DA:30,0
|
||||
DA:31,0
|
||||
DA:32,0
|
||||
DA:33,0
|
||||
DA:34,0
|
||||
DA:35,0
|
||||
DA:36,0
|
||||
DA:37,0
|
||||
DA:38,0
|
||||
DA:39,0
|
||||
DA:40,0
|
||||
DA:41,0
|
||||
DA:42,0
|
||||
DA:43,0
|
||||
DA:44,0
|
||||
DA:45,0
|
||||
DA:46,0
|
||||
DA:47,0
|
||||
DA:48,0
|
||||
DA:49,0
|
||||
DA:50,0
|
||||
DA:51,0
|
||||
DA:52,0
|
||||
DA:53,0
|
||||
DA:54,0
|
||||
DA:55,0
|
||||
DA:56,0
|
||||
DA:57,0
|
||||
DA:58,0
|
||||
DA:59,0
|
||||
DA:60,0
|
||||
DA:61,0
|
||||
DA:62,0
|
||||
DA:63,0
|
||||
DA:64,0
|
||||
DA:65,0
|
||||
DA:66,0
|
||||
DA:67,0
|
||||
DA:68,0
|
||||
DA:69,0
|
||||
DA:70,0
|
||||
LF:70
|
||||
LH:0
|
||||
BRDA:1,0,0,0
|
||||
BRF:1
|
||||
BRH:0
|
||||
FN:67,Object.<anonymous>
|
||||
FN:67,Object.<anonymous>.__setModuleDefault
|
||||
FN:67,Object.<anonymous>.__importStar
|
||||
FN:67,Object.<anonymous>.__awaiter
|
||||
FN:67,adopt
|
||||
FN:67,fulfilled
|
||||
FN:67,rejected
|
||||
FN:67,step
|
||||
FN:67,Object.<anonymous>.__importDefault
|
||||
FN:20,CreateUserService
|
||||
FNF:10
|
||||
FNH:9
|
||||
FNDA:1,Object.<anonymous>
|
||||
FNDA:0,Object.<anonymous>.__setModuleDefault
|
||||
FNDA:1,Object.<anonymous>.__importStar
|
||||
FNDA:10,Object.<anonymous>.__awaiter
|
||||
FNDA:13,adopt
|
||||
FNDA:10,fulfilled
|
||||
FNDA:1,rejected
|
||||
FNDA:20,step
|
||||
FNDA:2,Object.<anonymous>.__importDefault
|
||||
FNDA:5,CreateUserService
|
||||
DA:1,1
|
||||
DA:2,1
|
||||
DA:3,1
|
||||
DA:4,1
|
||||
DA:5,1
|
||||
DA:6,1
|
||||
DA:7,1
|
||||
DA:8,1
|
||||
DA:9,1
|
||||
DA:10,1
|
||||
DA:11,1
|
||||
DA:12,1
|
||||
DA:13,1
|
||||
DA:14,1
|
||||
DA:15,1
|
||||
DA:16,1
|
||||
DA:17,1
|
||||
DA:18,1
|
||||
DA:19,1
|
||||
DA:20,1
|
||||
DA:21,5
|
||||
DA:22,5
|
||||
DA:23,5
|
||||
DA:24,5
|
||||
DA:25,5
|
||||
DA:26,5
|
||||
DA:27,5
|
||||
DA:28,5
|
||||
DA:29,5
|
||||
DA:30,5
|
||||
DA:31,5
|
||||
DA:32,5
|
||||
DA:33,5
|
||||
DA:34,5
|
||||
DA:35,5
|
||||
DA:36,5
|
||||
DA:37,5
|
||||
DA:38,4
|
||||
DA:39,4
|
||||
DA:40,5
|
||||
DA:41,5
|
||||
DA:42,5
|
||||
DA:43,5
|
||||
DA:44,5
|
||||
DA:45,5
|
||||
DA:46,5
|
||||
DA:47,1
|
||||
DA:48,1
|
||||
DA:49,3
|
||||
DA:50,3
|
||||
DA:51,3
|
||||
DA:52,3
|
||||
DA:53,3
|
||||
DA:54,3
|
||||
DA:55,3
|
||||
DA:56,3
|
||||
DA:57,3
|
||||
DA:58,3
|
||||
DA:59,3
|
||||
DA:60,3
|
||||
DA:61,3
|
||||
DA:62,3
|
||||
DA:63,3
|
||||
DA:64,3
|
||||
DA:65,3
|
||||
DA:66,1
|
||||
DA:67,1
|
||||
LF:67
|
||||
LH:67
|
||||
BRDA:67,0,0,1
|
||||
BRDA:67,1,0,1
|
||||
BRDA:67,2,0,0
|
||||
BRDA:67,3,0,0
|
||||
BRDA:67,4,0,0
|
||||
BRDA:67,5,0,0
|
||||
BRDA:67,6,0,0
|
||||
BRDA:67,7,0,1
|
||||
BRDA:67,8,0,0
|
||||
BRDA:67,9,0,10
|
||||
BRDA:67,10,0,13
|
||||
BRDA:67,11,0,5
|
||||
BRDA:67,12,0,8
|
||||
BRDA:67,13,0,8
|
||||
BRDA:67,14,0,10
|
||||
BRDA:67,15,0,10
|
||||
BRDA:67,16,0,0
|
||||
BRDA:67,17,0,1
|
||||
BRDA:67,18,0,0
|
||||
BRDA:67,19,0,20
|
||||
BRDA:67,20,0,7
|
||||
BRDA:67,21,0,13
|
||||
BRDA:67,22,0,2
|
||||
BRDA:67,23,0,0
|
||||
BRDA:20,24,0,5
|
||||
BRDA:25,25,0,5
|
||||
BRDA:45,26,0,3
|
||||
BRDA:46,27,0,1
|
||||
BRDA:48,28,0,3
|
||||
BRDA:34,29,0,5
|
||||
BRDA:34,30,0,5
|
||||
BRDA:37,31,0,4
|
||||
BRF:32
|
||||
BRH:23
|
||||
end_of_record
|
||||
TN:
|
||||
SF:src/services/UserServices/DeleteUserService.ts
|
||||
|
||||
@@ -8,7 +8,7 @@ module.exports = {
|
||||
// automock: false,
|
||||
|
||||
// Stop running tests after `n` failures
|
||||
bail: 1,
|
||||
// bail: 0,
|
||||
|
||||
// The directory where Jest should store its cached dependency information
|
||||
// cacheDirectory: "/tmp/jest_rs",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"watch": "tsc -w",
|
||||
"start": "nodemon dist/server.js",
|
||||
"dev:server": "ts-node-dev --respawn --transpile-only --ignore node_modules src/server.ts",
|
||||
"pretest": "NODE_ENV=test sequelize db:migrate",
|
||||
"pretest": "NODE_ENV=test sequelize db:migrate && NODE_ENV=test sequelize db:seed:all",
|
||||
"test": "NODE_ENV=test jest",
|
||||
"posttest": "NODE_ENV=test sequelize db:migrate:undo:all"
|
||||
},
|
||||
@@ -42,11 +42,14 @@
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
"@types/cors": "^2.8.7",
|
||||
"@types/express": "^4.17.8",
|
||||
"@types/factory-girl": "^5.0.2",
|
||||
"@types/faker": "^5.1.3",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/multer": "^1.4.4",
|
||||
"@types/node": "^14.11.8",
|
||||
"@types/socket.io": "^2.1.11",
|
||||
"@types/supertest": "^2.0.10",
|
||||
"@types/validator": "^13.1.0",
|
||||
"@types/yup": "^0.29.8",
|
||||
"@typescript-eslint/eslint-plugin": "^4.4.0",
|
||||
@@ -57,9 +60,12 @@
|
||||
"eslint-import-resolver-typescript": "^2.3.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"factory-girl": "^5.0.4",
|
||||
"faker": "^5.1.0",
|
||||
"jest": "^26.6.0",
|
||||
"nodemon": "^2.0.4",
|
||||
"prettier": "^2.1.2",
|
||||
"supertest": "^5.0.0",
|
||||
"ts-jest": "^26.4.1",
|
||||
"ts-node-dev": "^1.0.0-pre.63",
|
||||
"typescript": "^4.0.3"
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
test("sum two number", () => {
|
||||
expect(1 + 2).toBe(3);
|
||||
});
|
||||
41
backend/src/__tests__/unit/CreateUserService.spec.ts
Normal file
41
backend/src/__tests__/unit/CreateUserService.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { disconnect, truncate } from "../utils/database";
|
||||
// import User from "../../models/User";
|
||||
// import app from "../../app";
|
||||
import CreateUserService from "../../services/UserServices/CreateUserService";
|
||||
import AppError from "../../errors/AppError";
|
||||
|
||||
describe("User", () => {
|
||||
beforeEach(async () => {
|
||||
await truncate();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await disconnect();
|
||||
});
|
||||
|
||||
it("should be able to create a new user", async () => {
|
||||
const user = await CreateUserService({
|
||||
name: "dasdas",
|
||||
email: "tesssst@test.com",
|
||||
password: "passwo22221131rd"
|
||||
});
|
||||
|
||||
expect(user).toHaveProperty("id");
|
||||
});
|
||||
|
||||
it("should not be able to create a user with duplicated email", async () => {
|
||||
await CreateUserService({
|
||||
name: "dasdas",
|
||||
email: "tesssst@test.com",
|
||||
password: "passwo22221131rd"
|
||||
});
|
||||
|
||||
expect(
|
||||
CreateUserService({
|
||||
name: "dasdas",
|
||||
email: "tesssst@test.com",
|
||||
password: "passwo22221131rd"
|
||||
})
|
||||
).rejects.toBeInstanceOf(AppError);
|
||||
});
|
||||
});
|
||||
11
backend/src/__tests__/utils/database.ts
Normal file
11
backend/src/__tests__/utils/database.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import database from "../../database";
|
||||
|
||||
const truncate = async (): Promise<void> => {
|
||||
await database.sync({ force: true });
|
||||
};
|
||||
|
||||
const disconnect = async (): Promise<void> => {
|
||||
return database.connectionManager.close();
|
||||
};
|
||||
|
||||
export { truncate, disconnect };
|
||||
44
backend/src/app.ts
Normal file
44
backend/src/app.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import "./bootstrap";
|
||||
import "reflect-metadata";
|
||||
import "express-async-errors";
|
||||
import express, { Request, Response, NextFunction } from "express";
|
||||
import cors from "cors";
|
||||
import cookieParser from "cookie-parser";
|
||||
import multer from "multer";
|
||||
import * as Sentry from "@sentry/node";
|
||||
|
||||
import "./database";
|
||||
import uploadConfig from "./config/upload";
|
||||
import AppError from "./errors/AppError";
|
||||
import routes from "./routes";
|
||||
|
||||
Sentry.init({ dsn: process.env.SENTRY_DSN });
|
||||
|
||||
const upload = multer(uploadConfig);
|
||||
const app = express();
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
credentials: true,
|
||||
origin: process.env.FRONTEND_URL
|
||||
})
|
||||
);
|
||||
app.use(cookieParser());
|
||||
app.use(express.json());
|
||||
app.use(Sentry.Handlers.requestHandler());
|
||||
app.use(upload.single("media"));
|
||||
app.use("/public", express.static(uploadConfig.directory));
|
||||
app.use(routes);
|
||||
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
app.use(async (err: Error, req: Request, res: Response, _: NextFunction) => {
|
||||
if (err instanceof AppError) {
|
||||
return res.status(err.statusCode).json({ error: err.message });
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "Internal server error" });
|
||||
});
|
||||
|
||||
export default app;
|
||||
@@ -1,51 +1,10 @@
|
||||
import "./bootstrap";
|
||||
import "reflect-metadata";
|
||||
import "express-async-errors";
|
||||
import express, { Request, Response, NextFunction } from "express";
|
||||
import cors from "cors";
|
||||
import cookieParser from "cookie-parser";
|
||||
import multer from "multer";
|
||||
import * as Sentry from "@sentry/node";
|
||||
|
||||
import "./database";
|
||||
import uploadConfig from "./config/upload";
|
||||
import AppError from "./errors/AppError";
|
||||
import routes from "./routes";
|
||||
import app from "./app";
|
||||
import { initIO } from "./libs/socket";
|
||||
import { StartWhatsAppSessions } from "./services/WbotServices/StartWhatsAppSessions";
|
||||
|
||||
Sentry.init({ dsn: process.env.SENTRY_DSN });
|
||||
|
||||
const upload = multer(uploadConfig);
|
||||
const app = express();
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
credentials: true,
|
||||
origin: process.env.FRONTEND_URL
|
||||
})
|
||||
);
|
||||
app.use(cookieParser());
|
||||
app.use(express.json());
|
||||
app.use(Sentry.Handlers.requestHandler());
|
||||
app.use(upload.single("media"));
|
||||
app.use("/public", express.static(uploadConfig.directory));
|
||||
app.use(routes);
|
||||
|
||||
const server = app.listen(process.env.PORT, () => {
|
||||
console.log(`Server started on port: ${process.env.PORT}`);
|
||||
});
|
||||
|
||||
initIO(server);
|
||||
StartWhatsAppSessions();
|
||||
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
app.use(async (err: Error, req: Request, res: Response, _: NextFunction) => {
|
||||
if (err instanceof AppError) {
|
||||
return res.status(err.statusCode).json({ error: err.message });
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "Internal server error" });
|
||||
});
|
||||
|
||||
@@ -32,13 +32,10 @@ const CreateUserService = async ({
|
||||
"Check-email",
|
||||
"An user with this email already exists.",
|
||||
async value => {
|
||||
if (value) {
|
||||
const emailExists = await User.findOne({
|
||||
where: { email: value }
|
||||
});
|
||||
return !emailExists;
|
||||
}
|
||||
return false;
|
||||
const emailExists = await User.findOne({
|
||||
where: { email: value! }
|
||||
});
|
||||
return !emailExists;
|
||||
}
|
||||
),
|
||||
password: Yup.string().required().min(5)
|
||||
|
||||
Reference in New Issue
Block a user