diff --git a/src/handlers/handlers.ts b/src/handlers/handlers.ts index 7cd96419d5619b3fea8da04999d6b14f3dcc9905..2cabcc678a64422dcbc97a40ed2097da186111e8 100644 --- a/src/handlers/handlers.ts +++ b/src/handlers/handlers.ts @@ -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.green('\nVotre association a été créée !!\n')) - } catch { - console.log(chalk.bgRedBright("\nErreur lors de la création de l'association\n")) + console.log(chalk.bgGreenBright('\nVotre 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.green('\nVotre token a été créé !!\n')) - } catch { - console.log(chalk.bgRedBright('\nErreur lors de la création du token\n')) + console.log(chalk.bgGreenBright('\nVotre 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.bgRedBright('\nErreur 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.green('\nVous avez soumis une proposition !!\n')) - } catch { - console.log(chalk.bgRedBright('\nErreur lors de la création de la proposition\n')) + console.log(chalk.bgGreenBright('\nVous 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("\nVous avez rejoint l'association !!\n")) - } catch { - // ERREUR -> PAS ASSEZ DE TOKEN - // ERREUR -> ASSOCIATION NON EXISTANTE - console.log(chalk.bgRedBright("\nErreur lors de l'inscription à l'association\n")) + console.log(chalk.bgGreenBright("\nVous 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.bgRedBright('\nErreur 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.bgRedBright("\nErreur 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.green('\nVous avez bruler vos tokens !!\n')) - } catch { - console.log(chalk.bgRedBright('\nErreur lors de la brulure de vos tokens\n')) + console.log(chalk.bgGreenBright('\nVous avez bruler vos tokens !!\n')) + } catch (error) { + console.log(chalk.bgRed(`\n${error.lastError.with.string}\n`)) } } diff --git a/src/services/association.service.ts b/src/services/association.service.ts index 23c065a5dbd0bd571377339e41fa28e272183fe6..bdd2c59d3d7c6e7c8672aca4c3cde72110836965 100644 --- a/src/services/association.service.ts +++ b/src/services/association.service.ts @@ -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 = 'KT1PCg4GbtF5LQQhHmY4t1qNYVspnitKGHgm' +const address = 'KT1NMZvpAEQmezU8kHKzgi9PjysoH4VTcB3P' // NEED UPDATE ENTRYPOINT !! async function createAssociation (association: Association, tezos: TezosToolkit): Promise<Operation> { diff --git a/test/handlers/handlers.spec.ts b/test/handlers/handlers.spec.ts index 7a84e7929cb9c7d4e2b1320a4ac45d17cacfa5c7..07cb5db29069134a970082569a83c253a45ae2c3 100644 --- a/test/handlers/handlers.spec.ts +++ b/test/handlers/handlers.spec.ts @@ -76,13 +76,20 @@ describe('handlers', () => { { name: 'Association Name', description: 'Association Description' }, mockedTezosToolkit ) - expect(consoleSpy).toBeCalledWith(chalk.green('\nVotre association a été créée !!\n')) + expect(consoleSpy).toBeCalledWith(chalk.bgGreenBright('\nVotre 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.bgRedBright("\nErreur lors de la création de l'association\n")) + expect(consoleSpy).toBeCalledWith(chalk.bgRed('\nCustom Error\n')) }) }) }) @@ -113,13 +120,20 @@ describe('handlers', () => { await handleCreateToken(mockedTezosToolkit) expect(createFATokenSpy).toBeCalledWith(nbTokenFungible, mockedTezosToolkit) - expect(consoleSpy).toBeCalledWith(chalk.green('\nVotre token a été créé !!\n')) + expect(consoleSpy).toBeCalledWith(chalk.bgGreenBright('\nVotre 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.green('\nErreur lors de la création du token\n')) + expect(consoleSpy).toBeCalledWith(chalk.red('\nCustom 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.bgRedBright('\nErreur lors de la récupération de votre portefeuille\n')) + expect(consoleSpy).toBeCalledWith(chalk.bgRed('\nCustom 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.green('\nVous avez soumis une proposition !!\n')) + expect(consoleSpy).toBeCalledWith(chalk.bgGreenBright('\nVous 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.bgRedBright('\nErreur lors de la création de la proposition\n')) + expect(consoleSpy).toBeCalledWith(chalk.bgRed('\nCustom Error\n')) }) }) }) @@ -200,13 +228,20 @@ describe('handlers', () => { await handleJoinAssociation(mockedTezosToolkit) expect(joinAssociationSpy).toBeCalledWith('Association Name', mockedTezosToolkit) - expect(consoleSpy).toBeCalledWith(chalk.green("\nVous avez rejoint l'association !!\n")) + expect(consoleSpy).toBeCalledWith(chalk.bgGreenBright("\nVous 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.bgRedBright("\nErreur lors de l'inscription à l'association\n")) + expect(consoleSpy).toBeCalledWith(chalk.bgRed('\nCustom 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.bgRedBright('\nErreur lors de la récupération des associations\n')) + expect(consoleSpy).toBeCalledWith(chalk.bgRed('\nCustom 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.bgRedBright("\nErreur lors de la récupération des détails de l'association\n")) + expect(consoleSpy).toBeCalledWith(chalk.bgRed('\nCustom Error\n')) }) }) }) @@ -282,13 +331,20 @@ describe('handlers', () => { await handleBurnToken(mockedTezosToolkit) expect(burnTokenSpy).toBeCalledWith(nbTokenToBurn, mockedTezosToolkit) - expect(consoleSpy).toBeCalledWith(chalk.green('\nVous avez bruler vos tokens !!\n')) + expect(consoleSpy).toBeCalledWith(chalk.bgGreenBright('\nVous 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.bgRedBright('\nErreur lors de la brulure de vos tokens\n')) + expect(consoleSpy).toBeCalledWith(chalk.bgRed('\nCustom Error\n')) }) }) })