Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QSI_Groupe4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lydia Tarmelit
QSI_Groupe4
Commits
b9d4e722
Commit
b9d4e722
authored
1 year ago
by
Nawfel Senoussi
Browse files
Options
Downloads
Patches
Plain Diff
improve error handling
parent
84645c1e
Branches
main
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/handlers/handlers.ts
+21
-29
21 additions, 29 deletions
src/handlers/handlers.ts
src/services/association.service.ts
+1
-1
1 addition, 1 deletion
src/services/association.service.ts
test/handlers/handlers.spec.ts
+77
-21
77 additions, 21 deletions
test/handlers/handlers.spec.ts
with
99 additions
and
51 deletions
src/handlers/handlers.ts
+
21
−
29
View file @
b9d4e722
...
...
@@ -60,13 +60,12 @@ async function handleCreateAssociation (tezos: TezosToolkit): Promise<void> {
}
})
console
.
log
(
"
Création de l'association en cours...
"
)
try
{
const
op
=
await
createAssociation
(
association
,
tezos
)
console
.
log
(
op
.
hash
)
console
.
log
(
chalk
.
g
reen
(
'
\n
Votre association a été créée !!
\n
'
))
}
catch
{
console
.
log
(
chalk
.
bgRed
Bright
(
"
\n
Erreur lors de la création de l'association
\n
"
))
console
.
log
(
chalk
.
bgG
reen
Bright
(
'
\n
Votre association a été créée !!
\n
'
))
}
catch
(
error
)
{
console
.
log
(
chalk
.
bgRed
(
`\n
${
error
.
lastError
.
with
.
string
}
\n
`
))
}
}
...
...
@@ -103,9 +102,9 @@ async function handleCreateToken (tezos: TezosToolkit): Promise<void> {
try
{
const
op
=
await
createFAToken
(
nbTokenFungible
,
tezos
)
console
.
log
(
op
.
hash
)
console
.
log
(
chalk
.
g
reen
(
'
\n
Votre token a été créé !!
\n
'
))
}
catch
{
console
.
log
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la création du token
\n
'
))
console
.
log
(
chalk
.
bgG
reen
Bright
(
'
\n
Votre token a été créé !!
\n
'
))
}
catch
(
error
)
{
console
.
log
(
chalk
.
bgRed
(
`\n
${
error
.
lastError
.
with
.
string
}
\n
`
))
}
}
...
...
@@ -118,8 +117,8 @@ async function handleGetBalance (tezos: TezosToolkit): Promise<void> {
try
{
const
balance
=
await
getBalance
(
tezos
)
console
.
log
(
`\nSolde du portefeuille:
${
balance
}
ꜩ\n`
)
}
catch
{
console
.
log
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la récupération de votre portefeuille
\n
'
))
}
catch
(
error
)
{
console
.
log
(
chalk
.
bgRed
(
`\n
${
error
.
lastError
.
with
.
string
}
\n
`
))
}
}
...
...
@@ -170,12 +169,11 @@ async function handleCreateProposal (tezos: TezosToolkit): Promise<void> {
})
try
{
console
.
log
(
'
Création de la proposition en cours...
'
)
const
op
=
await
createProposal
(
proposal
,
tezos
)
console
.
log
(
op
.
hash
)
console
.
log
(
chalk
.
g
reen
(
'
\n
Vous avez soumis une proposition !!
\n
'
))
}
catch
{
console
.
log
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la création de la proposition
\n
'
))
console
.
log
(
chalk
.
bgG
reen
Bright
(
'
\n
Vous avez soumis une proposition !!
\n
'
))
}
catch
(
error
)
{
console
.
log
(
chalk
.
bgRed
(
`\n
${
error
.
lastError
.
with
.
string
}
\n
`
))
}
}
...
...
@@ -209,14 +207,11 @@ async function handleJoinAssociation (tezos: TezosToolkit): Promise<void> {
})
try
{
console
.
log
(
"
Inscription à l'association en cours...
"
)
const
op
=
await
joinAssociation
(
associationName
,
tezos
)
console
.
log
(
op
.
hash
)
console
.
log
(
chalk
.
green
(
"
\n
Vous avez rejoint l'association !!
\n
"
))
}
catch
{
// ERREUR -> PAS ASSEZ DE TOKEN
// ERREUR -> ASSOCIATION NON EXISTANTE
console
.
log
(
chalk
.
bgRedBright
(
"
\n
Erreur lors de l'inscription à l'association
\n
"
))
console
.
log
(
chalk
.
bgGreenBright
(
"
\n
Vous avez rejoint l'association !!
\n
"
))
}
catch
(
error
)
{
console
.
log
(
chalk
.
bgRed
(
`\n
${
error
.
lastError
.
with
.
string
}
\n`
))
}
}
...
...
@@ -227,12 +222,11 @@ async function handleJoinAssociation (tezos: TezosToolkit): Promise<void> {
*/
async
function
handleGetAssociations
(
tezos
:
TezosToolkit
):
Promise
<
void
>
{
try
{
console
.
log
(
'
Récupération des associations en cours...
'
)
const
op
=
await
getAssociations
(
tezos
)
console
.
log
(
op
.
hash
)
// LISTER LES ASSOCIATIONS
}
catch
{
console
.
log
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la récupération des associations
\n
'
))
}
catch
(
error
)
{
console
.
log
(
chalk
.
bgRed
(
`\n
${
error
.
lastError
.
with
.
string
}
\n
`
))
}
}
...
...
@@ -266,12 +260,11 @@ async function handleGetAssociationDetails (tezos: TezosToolkit): Promise<void>
})
try
{
console
.
log
(
"
Récupération des détails de l'association en cours...
"
)
const
op
=
await
getAssociationDetails
(
associationName
,
tezos
)
console
.
log
(
op
.
hash
)
// RETURN ASSOCIATIONS
}
catch
{
console
.
log
(
chalk
.
bgRed
Bright
(
"
\n
Erreur lors de la récupération des détails de l'association
\n
"
))
}
catch
(
error
)
{
console
.
log
(
chalk
.
bgRed
(
`\n
${
error
.
lastError
.
with
.
string
}
\n
`
))
}
}
...
...
@@ -306,12 +299,11 @@ async function handleBurnToken (tezos: TezosToolkit): Promise<void> {
})
try
{
console
.
log
(
'
Brulure des tokens en cours...
'
)
const
op
=
await
burnToken
(
nbTokenToBurn
,
tezos
)
console
.
log
(
op
.
hash
)
console
.
log
(
chalk
.
g
reen
(
'
\n
Vous avez bruler vos tokens !!
\n
'
))
}
catch
{
console
.
log
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la brulure de vos tokens
\n
'
))
console
.
log
(
chalk
.
bgG
reen
Bright
(
'
\n
Vous avez bruler vos tokens !!
\n
'
))
}
catch
(
error
)
{
console
.
log
(
chalk
.
bgRed
(
`\n
${
error
.
lastError
.
with
.
string
}
\n
`
))
}
}
...
...
This diff is collapsed.
Click to expand it.
src/services/association.service.ts
+
1
−
1
View file @
b9d4e722
...
...
@@ -2,7 +2,7 @@ import { type Operation, type TezosToolkit } from '@taquito/taquito'
import
{
type
Association
}
from
'
../types/Association
'
// NEED UPDATE ADDRESS !! (SMART CONTRACT 1: Registre des associations)
const
address
=
'
KT1
PCg4GbtF5LQQhHmY4t1qNYVspnitKGHgm
'
const
address
=
'
KT1
NMZvpAEQmezU8kHKzgi9PjysoH4VTcB3P
'
// NEED UPDATE ENTRYPOINT !!
async
function
createAssociation
(
association
:
Association
,
tezos
:
TezosToolkit
):
Promise
<
Operation
>
{
...
...
This diff is collapsed.
Click to expand it.
test/handlers/handlers.spec.ts
+
77
−
21
View file @
b9d4e722
...
...
@@ -76,13 +76,20 @@ describe('handlers', () => {
{
name
:
'
Association Name
'
,
description
:
'
Association Description
'
},
mockedTezosToolkit
)
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
g
reen
(
'
\n
Votre association a été créée !!
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgG
reen
Bright
(
'
\n
Votre association a été créée !!
\n
'
))
})
})
describe
(
'
when createAssociation is called with error
'
,
()
=>
{
it
(
'
should log error message
'
,
async
()
=>
{
createAssociationSpy
.
mockRejectedValueOnce
({})
const
error
=
{
lastError
:
{
with
:
{
string
:
'
Custom Error
'
}
}
}
createAssociationSpy
.
mockRejectedValueOnce
(
error
)
const
name
=
'
Association Name
'
const
description
=
'
Association Description
'
...
...
@@ -97,7 +104,7 @@ describe('handlers', () => {
{
name
:
'
Association Name
'
,
description
:
'
Association Description
'
},
mockedTezosToolkit
)
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
Bright
(
"
\n
Erreur lors de la création de l'association
\n
"
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
(
'
\n
Custom Error
\n
'
))
})
})
})
...
...
@@ -113,13 +120,20 @@ describe('handlers', () => {
await
handleCreateToken
(
mockedTezosToolkit
)
expect
(
createFATokenSpy
).
toBeCalledWith
(
nbTokenFungible
,
mockedTezosToolkit
)
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
g
reen
(
'
\n
Votre token a été créé !!
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgG
reen
Bright
(
'
\n
Votre token a été créé !!
\n
'
))
})
})
describe
(
'
when createFAToken is called with error
'
,
()
=>
{
it
(
'
should log error message
'
,
async
()
=>
{
createAssociationSpy
.
mockRejectedValueOnce
({})
const
error
=
{
lastError
:
{
with
:
{
string
:
'
Custom Error
'
}
}
}
createAssociationSpy
.
mockRejectedValueOnce
(
error
)
const
nbTokenFungible
=
5
const
consoleSpy
=
vi
.
spyOn
(
console
,
'
log
'
).
mockImplementation
(()
=>
{})
...
...
@@ -128,7 +142,7 @@ describe('handlers', () => {
await
handleCreateToken
(
mockedTezosToolkit
)
expect
(
createAssociationSpy
).
toBeCalledWith
(
nbTokenFungible
,
mockedTezosToolkit
)
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
g
re
en
(
'
\n
Erreur lors de la création du token
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
re
d
(
'
\n
Custom Error
\n
'
))
})
})
})
...
...
@@ -144,14 +158,21 @@ describe('handlers', () => {
describe
(
'
when getBalance is called with error
'
,
()
=>
{
it
(
'
should log error message
'
,
async
()
=>
{
getBalanceSpy
.
mockRejectedValueOnce
({})
const
error
=
{
lastError
:
{
with
:
{
string
:
'
Custom Error
'
}
}
}
getBalanceSpy
.
mockRejectedValueOnce
(
error
)
const
consoleSpy
=
vi
.
spyOn
(
console
,
'
log
'
).
mockImplementation
(()
=>
{})
await
handleGetBalance
(
mockedTezosToolkit
)
expect
(
getBalanceSpy
).
toBeCalled
()
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la récupération de votre portefeuille
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
(
'
\n
Custom Error
\n
'
))
})
})
})
...
...
@@ -168,13 +189,20 @@ describe('handlers', () => {
await
handleCreateProposal
(
mockedTezosToolkit
)
expect
(
createProposalSpy
).
toBeCalledWith
({
title
:
'
Proposal Title
'
,
description
:
'
Proposal Description
'
},
mockedTezosToolkit
)
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
g
reen
(
'
\n
Vous avez soumis une proposition !!
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgG
reen
Bright
(
'
\n
Vous avez soumis une proposition !!
\n
'
))
})
})
describe
(
'
when createProposal is called with error
'
,
()
=>
{
it
(
'
should log error message
'
,
async
()
=>
{
createProposalSpy
.
mockRejectedValueOnce
({})
const
error
=
{
lastError
:
{
with
:
{
string
:
'
Custom Error
'
}
}
}
createProposalSpy
.
mockRejectedValueOnce
(
error
)
const
title
=
'
Proposal Title
'
const
description
=
'
Proposal Description
'
...
...
@@ -184,7 +212,7 @@ describe('handlers', () => {
await
handleCreateProposal
(
mockedTezosToolkit
)
expect
(
createProposalSpy
).
toBeCalled
()
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la création de la proposition
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
(
'
\n
Custom Error
\n
'
))
})
})
})
...
...
@@ -200,13 +228,20 @@ describe('handlers', () => {
await
handleJoinAssociation
(
mockedTezosToolkit
)
expect
(
joinAssociationSpy
).
toBeCalledWith
(
'
Association Name
'
,
mockedTezosToolkit
)
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
g
reen
(
"
\n
Vous avez rejoint l'association !!
\n
"
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgG
reen
Bright
(
"
\n
Vous avez rejoint l'association !!
\n
"
))
})
})
describe
(
'
when joinAssociation is called with error
'
,
()
=>
{
it
(
'
should log error message
'
,
async
()
=>
{
joinAssociationSpy
.
mockRejectedValueOnce
({})
const
error
=
{
lastError
:
{
with
:
{
string
:
'
Custom Error
'
}
}
}
joinAssociationSpy
.
mockRejectedValueOnce
(
error
)
const
name
=
'
Association Name
'
const
consoleSpy
=
vi
.
spyOn
(
console
,
'
log
'
).
mockImplementation
(()
=>
{})
...
...
@@ -215,7 +250,7 @@ describe('handlers', () => {
await
handleJoinAssociation
(
mockedTezosToolkit
)
expect
(
joinAssociationSpy
).
toBeCalled
()
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
Bright
(
"
\n
Erreur lors de l'inscription à l'association
\n
"
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
(
'
\n
Custom Error
\n
'
))
})
})
})
...
...
@@ -231,14 +266,21 @@ describe('handlers', () => {
describe
(
'
when getAssociations is called with error
'
,
()
=>
{
it
(
'
should log error message
'
,
async
()
=>
{
getAssociationsSpy
.
mockRejectedValueOnce
({})
const
error
=
{
lastError
:
{
with
:
{
string
:
'
Custom Error
'
}
}
}
getAssociationsSpy
.
mockRejectedValueOnce
(
error
)
const
consoleSpy
=
vi
.
spyOn
(
console
,
'
log
'
).
mockImplementation
(()
=>
{})
await
handleGetAssociations
(
mockedTezosToolkit
)
expect
(
getAssociationsSpy
).
toBeCalled
()
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la récupération des associations
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
(
'
\n
Custom Error
\n
'
))
})
})
})
...
...
@@ -257,7 +299,14 @@ describe('handlers', () => {
describe
(
'
when getAssociationDetails is called with error
'
,
()
=>
{
it
(
'
should log error message
'
,
async
()
=>
{
getAssociationDetailsSpy
.
mockRejectedValueOnce
({})
const
error
=
{
lastError
:
{
with
:
{
string
:
'
Custom Error
'
}
}
}
getAssociationDetailsSpy
.
mockRejectedValueOnce
(
error
)
const
associationName
=
'
Association Name
'
const
consoleSpy
=
vi
.
spyOn
(
console
,
'
log
'
).
mockImplementation
(()
=>
{})
...
...
@@ -266,7 +315,7 @@ describe('handlers', () => {
await
handleGetAssociationDetails
(
mockedTezosToolkit
)
expect
(
getAssociationDetailsSpy
).
toBeCalled
()
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
Bright
(
"
\n
Erreur lors de la récupération des détails de l'association
\n
"
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
(
'
\n
Custom Error
\n
'
))
})
})
})
...
...
@@ -282,13 +331,20 @@ describe('handlers', () => {
await
handleBurnToken
(
mockedTezosToolkit
)
expect
(
burnTokenSpy
).
toBeCalledWith
(
nbTokenToBurn
,
mockedTezosToolkit
)
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
g
reen
(
'
\n
Vous avez bruler vos tokens !!
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgG
reen
Bright
(
'
\n
Vous avez bruler vos tokens !!
\n
'
))
})
})
describe
(
'
when burnToken is called with error
'
,
()
=>
{
it
(
'
should log error message
'
,
async
()
=>
{
burnTokenSpy
.
mockRejectedValueOnce
({})
const
error
=
{
lastError
:
{
with
:
{
string
:
'
Custom Error
'
}
}
}
burnTokenSpy
.
mockRejectedValueOnce
(
error
)
const
nbTokenToBurn
=
5
const
consoleSpy
=
vi
.
spyOn
(
console
,
'
log
'
).
mockImplementation
(()
=>
{})
...
...
@@ -297,7 +353,7 @@ describe('handlers', () => {
await
handleBurnToken
(
mockedTezosToolkit
)
expect
(
burnTokenSpy
).
toBeCalledWith
(
nbTokenToBurn
,
mockedTezosToolkit
)
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
Bright
(
'
\n
Erreur lors de la brulure de vos tokens
\n
'
))
expect
(
consoleSpy
).
toBeCalledWith
(
chalk
.
bgRed
(
'
\n
Custom Error
\n
'
))
})
})
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment