diff --git a/test/handlers/handlers.spec.ts b/test/handlers/handlers.spec.ts index 9d8a3b213949c11317c0be59bfc35f21d022ebb6..7a84e7929cb9c7d4e2b1320a4ac45d17cacfa5c7 100644 --- a/test/handlers/handlers.spec.ts +++ b/test/handlers/handlers.spec.ts @@ -7,21 +7,30 @@ const { createAssociationSpy, promptSpy, createFATokenSpy, getBalanceSpy, create vi.hoisted(() => { return { createAssociationSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), - createFATokenSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), - getBalanceSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), - createProposalSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), + createFATokenSpy: vi.fn().mockResolvedValue({ hash: 'token-hash' }), + getBalanceSpy: vi.fn().mockResolvedValue({ hash: 'balance-hash' }), + createProposalSpy: vi.fn().mockResolvedValue({ hash: 'proposal-hash' }), joinAssociationSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), getAssociationsSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), getAssociationDetailsSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), - burnTokenSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), + burnTokenSpy: vi.fn().mockResolvedValue({ hash: 'token-hash' }), promptSpy: vi.fn().mockResolvedValue({}) } }) vi.mock('inquirer', async (importOriginal) => { const actual = await importOriginal() - actual.default.prompt = promptSpy - return actual + + if (typeof actual === 'object' && actual !== null) { + return { + ...actual, + default: { + prompt: promptSpy + } + } + } else { + return actual + } }) vi.mock('../../src/services/association.service', () => ({ diff --git a/test/handlers/roleHandlers.spec.ts b/test/handlers/roleHandlers.spec.ts index f83e3250af80ce949217c51e5b93167494ff2dcb..7c29272113b48c48132cbf212ba9796da2c0e9b4 100644 --- a/test/handlers/roleHandlers.spec.ts +++ b/test/handlers/roleHandlers.spec.ts @@ -19,39 +19,39 @@ const mockedTezosToolkit = {} as unknown as TezosToolkit describe('roleHandlers', () => { beforeEach(() => { vi.clearAllMocks() - }); + }) describe('handleAdminFATokenChoice', () => { - describe('when choice is "1"', () => { + describe('when choice is "Créer une association"', () => { it('should call handleCreateAssociation', async () => { await handleAdminFATokenChoice('Créer une association', mockedTezosToolkit) expect(handleCreateAssociation).toBeCalled() - }); + }) }) - describe('when choice is "2"', () => { + describe('when choice is "Créer un token"', () => { it('should call handleCreateToken', async () => { await handleAdminFATokenChoice('Créer un token', mockedTezosToolkit) expect(handleCreateToken).toBeCalled() - }); + }) }) - describe('when choice is "3"', () => { + describe('when choice is "Bruler des tokens"', () => { it('should call handleBurnToken', async () => { await handleAdminFATokenChoice('Bruler des tokens', mockedTezosToolkit) expect(handleBurnToken).toBeCalled() - }); + }) }) - describe('when choice is "4"', () => { + describe('when choice is "Voir mon portefeuille"', () => { it('should call handleGetBalance', async () => { await handleAdminFATokenChoice('Voir mon portefeuille', mockedTezosToolkit) expect(handleGetBalance).toBeCalled() - }); + }) }) describe('when choice is invalid', () => { @@ -60,33 +60,33 @@ describe('roleHandlers', () => { await handleAdminFATokenChoice('invalid', mockedTezosToolkit) expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n')) - }); + }) }) - }); + }) describe('handleAdminAssociationChoice', () => { - describe('when choice is "1"', () => { + describe('when choice is "Créer un token"', () => { it('should call handleCreateToken', async () => { await handleAdminAssociationChoice('Créer un token', mockedTezosToolkit) expect(handleCreateToken).toBeCalled() - }); + }) }) - describe('when choice is "2"', () => { + describe('when choice is "Bruler des tokens"', () => { it('should call handleBurnToken', async () => { await handleAdminAssociationChoice('Bruler des tokens', mockedTezosToolkit) expect(handleBurnToken).toBeCalled() - }); + }) }) - describe('when choice is "3"', () => { + describe('when choice is "Voir mon portefeuille"', () => { it('should call handleGetBalance', async () => { await handleAdminAssociationChoice('Voir mon portefeuille', mockedTezosToolkit) expect(handleGetBalance).toBeCalled() - }); + }) }) describe('when choice is invalid', () => { @@ -95,33 +95,33 @@ describe('roleHandlers', () => { await handleAdminAssociationChoice('invalid', mockedTezosToolkit) expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n')) - }); + }) }) - }); + }) describe('handleAdherentChoice', () => { - describe('when choice is "1"', () => { + describe('when choice is "Faire une proposition"', () => { it('should call handleCreateProposal', async () => { await handleAdherentChoice('Faire une proposition', mockedTezosToolkit) expect(handleCreateProposal).toBeCalled() - }); + }) }) - describe('when choice is "2"', () => { + describe('when choice is "Créer un token"', () => { it('should call handleCreateToken', async () => { await handleAdherentChoice('Créer un token', mockedTezosToolkit) expect(handleCreateToken).toBeCalled() - }); + }) }) - describe('when choice is "3"', () => { + describe('when choice is "Voir mon portefeuille"', () => { it('should call handleGetBalance', async () => { await handleAdherentChoice('Voir mon portefeuille', mockedTezosToolkit) expect(handleGetBalance).toBeCalled() - }); + }) }) describe('when choice is invalid', () => { @@ -130,41 +130,41 @@ describe('roleHandlers', () => { await handleAdherentChoice('invalid', mockedTezosToolkit) expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n')) - }); + }) }) - }); + }) describe('handleConnectedChoice', () => { - describe('when choice is "1"', () => { + describe('when choice is "Rejoindre une association"', () => { it('should call handleJoinAssociation', async () => { await handleConnectedChoice('Rejoindre une association', mockedTezosToolkit) expect(handleJoinAssociation).toBeCalled() - }); + }) }) - describe('when choice is "2"', () => { + describe('when choice is "Créer un token"', () => { it('should call handleCreateToken', async () => { await handleConnectedChoice('Créer un token', mockedTezosToolkit) expect(handleCreateToken).toBeCalled() - }); + }) }) - describe('when choice is "3"', () => { + describe('when choice is "Voir les associations"', () => { it('should call handleGetAssociations', async () => { await handleConnectedChoice('Voir les associations', mockedTezosToolkit) expect(handleGetAssociations).toBeCalled() - }); + }) }) - describe('when choice is "4"', () => { + describe('when choice is "Voir mon portefeuille"', () => { it('should call handleGetBalance', async () => { await handleConnectedChoice('Voir mon portefeuille', mockedTezosToolkit) expect(handleGetBalance).toBeCalled() - }); + }) }) describe('when choice is invalid', () => { @@ -173,7 +173,7 @@ describe('roleHandlers', () => { await handleConnectedChoice('invalid', mockedTezosToolkit) expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n')) - }); + }) }) - }); + }) })