Skip to content
Snippets Groups Projects
Commit 84645c1e authored by Nawfel Senoussi's avatar Nawfel Senoussi
Browse files

update unit tests

parent de493816
Branches
No related tags found
No related merge requests found
...@@ -7,21 +7,30 @@ const { createAssociationSpy, promptSpy, createFATokenSpy, getBalanceSpy, create ...@@ -7,21 +7,30 @@ const { createAssociationSpy, promptSpy, createFATokenSpy, getBalanceSpy, create
vi.hoisted(() => { vi.hoisted(() => {
return { return {
createAssociationSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), createAssociationSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }),
createFATokenSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), createFATokenSpy: vi.fn().mockResolvedValue({ hash: 'token-hash' }),
getBalanceSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), getBalanceSpy: vi.fn().mockResolvedValue({ hash: 'balance-hash' }),
createProposalSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), createProposalSpy: vi.fn().mockResolvedValue({ hash: 'proposal-hash' }),
joinAssociationSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), joinAssociationSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }),
getAssociationsSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }), getAssociationsSpy: vi.fn().mockResolvedValue({ hash: 'association-hash' }),
getAssociationDetailsSpy: 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({}) promptSpy: vi.fn().mockResolvedValue({})
} }
}) })
vi.mock('inquirer', async (importOriginal) => { vi.mock('inquirer', async (importOriginal) => {
const actual = await 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', () => ({ vi.mock('../../src/services/association.service', () => ({
......
...@@ -19,39 +19,39 @@ const mockedTezosToolkit = {} as unknown as TezosToolkit ...@@ -19,39 +19,39 @@ const mockedTezosToolkit = {} as unknown as TezosToolkit
describe('roleHandlers', () => { describe('roleHandlers', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks() vi.clearAllMocks()
}); })
describe('handleAdminFATokenChoice', () => { describe('handleAdminFATokenChoice', () => {
describe('when choice is "1"', () => { describe('when choice is "Créer une association"', () => {
it('should call handleCreateAssociation', async () => { it('should call handleCreateAssociation', async () => {
await handleAdminFATokenChoice('Créer une association', mockedTezosToolkit) await handleAdminFATokenChoice('Créer une association', mockedTezosToolkit)
expect(handleCreateAssociation).toBeCalled() expect(handleCreateAssociation).toBeCalled()
}); })
}) })
describe('when choice is "2"', () => { describe('when choice is "Créer un token"', () => {
it('should call handleCreateToken', async () => { it('should call handleCreateToken', async () => {
await handleAdminFATokenChoice('Créer un token', mockedTezosToolkit) await handleAdminFATokenChoice('Créer un token', mockedTezosToolkit)
expect(handleCreateToken).toBeCalled() expect(handleCreateToken).toBeCalled()
}); })
}) })
describe('when choice is "3"', () => { describe('when choice is "Bruler des tokens"', () => {
it('should call handleBurnToken', async () => { it('should call handleBurnToken', async () => {
await handleAdminFATokenChoice('Bruler des tokens', mockedTezosToolkit) await handleAdminFATokenChoice('Bruler des tokens', mockedTezosToolkit)
expect(handleBurnToken).toBeCalled() expect(handleBurnToken).toBeCalled()
}); })
}) })
describe('when choice is "4"', () => { describe('when choice is "Voir mon portefeuille"', () => {
it('should call handleGetBalance', async () => { it('should call handleGetBalance', async () => {
await handleAdminFATokenChoice('Voir mon portefeuille', mockedTezosToolkit) await handleAdminFATokenChoice('Voir mon portefeuille', mockedTezosToolkit)
expect(handleGetBalance).toBeCalled() expect(handleGetBalance).toBeCalled()
}); })
}) })
describe('when choice is invalid', () => { describe('when choice is invalid', () => {
...@@ -60,33 +60,33 @@ describe('roleHandlers', () => { ...@@ -60,33 +60,33 @@ describe('roleHandlers', () => {
await handleAdminFATokenChoice('invalid', mockedTezosToolkit) await handleAdminFATokenChoice('invalid', mockedTezosToolkit)
expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n')) expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n'))
}); })
}) })
}); })
describe('handleAdminAssociationChoice', () => { describe('handleAdminAssociationChoice', () => {
describe('when choice is "1"', () => { describe('when choice is "Créer un token"', () => {
it('should call handleCreateToken', async () => { it('should call handleCreateToken', async () => {
await handleAdminAssociationChoice('Créer un token', mockedTezosToolkit) await handleAdminAssociationChoice('Créer un token', mockedTezosToolkit)
expect(handleCreateToken).toBeCalled() expect(handleCreateToken).toBeCalled()
}); })
}) })
describe('when choice is "2"', () => { describe('when choice is "Bruler des tokens"', () => {
it('should call handleBurnToken', async () => { it('should call handleBurnToken', async () => {
await handleAdminAssociationChoice('Bruler des tokens', mockedTezosToolkit) await handleAdminAssociationChoice('Bruler des tokens', mockedTezosToolkit)
expect(handleBurnToken).toBeCalled() expect(handleBurnToken).toBeCalled()
}); })
}) })
describe('when choice is "3"', () => { describe('when choice is "Voir mon portefeuille"', () => {
it('should call handleGetBalance', async () => { it('should call handleGetBalance', async () => {
await handleAdminAssociationChoice('Voir mon portefeuille', mockedTezosToolkit) await handleAdminAssociationChoice('Voir mon portefeuille', mockedTezosToolkit)
expect(handleGetBalance).toBeCalled() expect(handleGetBalance).toBeCalled()
}); })
}) })
describe('when choice is invalid', () => { describe('when choice is invalid', () => {
...@@ -95,33 +95,33 @@ describe('roleHandlers', () => { ...@@ -95,33 +95,33 @@ describe('roleHandlers', () => {
await handleAdminAssociationChoice('invalid', mockedTezosToolkit) await handleAdminAssociationChoice('invalid', mockedTezosToolkit)
expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n')) expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n'))
}); })
}) })
}); })
describe('handleAdherentChoice', () => { describe('handleAdherentChoice', () => {
describe('when choice is "1"', () => { describe('when choice is "Faire une proposition"', () => {
it('should call handleCreateProposal', async () => { it('should call handleCreateProposal', async () => {
await handleAdherentChoice('Faire une proposition', mockedTezosToolkit) await handleAdherentChoice('Faire une proposition', mockedTezosToolkit)
expect(handleCreateProposal).toBeCalled() expect(handleCreateProposal).toBeCalled()
}); })
}) })
describe('when choice is "2"', () => { describe('when choice is "Créer un token"', () => {
it('should call handleCreateToken', async () => { it('should call handleCreateToken', async () => {
await handleAdherentChoice('Créer un token', mockedTezosToolkit) await handleAdherentChoice('Créer un token', mockedTezosToolkit)
expect(handleCreateToken).toBeCalled() expect(handleCreateToken).toBeCalled()
}); })
}) })
describe('when choice is "3"', () => { describe('when choice is "Voir mon portefeuille"', () => {
it('should call handleGetBalance', async () => { it('should call handleGetBalance', async () => {
await handleAdherentChoice('Voir mon portefeuille', mockedTezosToolkit) await handleAdherentChoice('Voir mon portefeuille', mockedTezosToolkit)
expect(handleGetBalance).toBeCalled() expect(handleGetBalance).toBeCalled()
}); })
}) })
describe('when choice is invalid', () => { describe('when choice is invalid', () => {
...@@ -130,41 +130,41 @@ describe('roleHandlers', () => { ...@@ -130,41 +130,41 @@ describe('roleHandlers', () => {
await handleAdherentChoice('invalid', mockedTezosToolkit) await handleAdherentChoice('invalid', mockedTezosToolkit)
expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n')) expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n'))
}); })
}) })
}); })
describe('handleConnectedChoice', () => { describe('handleConnectedChoice', () => {
describe('when choice is "1"', () => { describe('when choice is "Rejoindre une association"', () => {
it('should call handleJoinAssociation', async () => { it('should call handleJoinAssociation', async () => {
await handleConnectedChoice('Rejoindre une association', mockedTezosToolkit) await handleConnectedChoice('Rejoindre une association', mockedTezosToolkit)
expect(handleJoinAssociation).toBeCalled() expect(handleJoinAssociation).toBeCalled()
}); })
}) })
describe('when choice is "2"', () => { describe('when choice is "Créer un token"', () => {
it('should call handleCreateToken', async () => { it('should call handleCreateToken', async () => {
await handleConnectedChoice('Créer un token', mockedTezosToolkit) await handleConnectedChoice('Créer un token', mockedTezosToolkit)
expect(handleCreateToken).toBeCalled() expect(handleCreateToken).toBeCalled()
}); })
}) })
describe('when choice is "3"', () => { describe('when choice is "Voir les associations"', () => {
it('should call handleGetAssociations', async () => { it('should call handleGetAssociations', async () => {
await handleConnectedChoice('Voir les associations', mockedTezosToolkit) await handleConnectedChoice('Voir les associations', mockedTezosToolkit)
expect(handleGetAssociations).toBeCalled() expect(handleGetAssociations).toBeCalled()
}); })
}) })
describe('when choice is "4"', () => { describe('when choice is "Voir mon portefeuille"', () => {
it('should call handleGetBalance', async () => { it('should call handleGetBalance', async () => {
await handleConnectedChoice('Voir mon portefeuille', mockedTezosToolkit) await handleConnectedChoice('Voir mon portefeuille', mockedTezosToolkit)
expect(handleGetBalance).toBeCalled() expect(handleGetBalance).toBeCalled()
}); })
}) })
describe('when choice is invalid', () => { describe('when choice is invalid', () => {
...@@ -173,7 +173,7 @@ describe('roleHandlers', () => { ...@@ -173,7 +173,7 @@ describe('roleHandlers', () => {
await handleConnectedChoice('invalid', mockedTezosToolkit) await handleConnectedChoice('invalid', mockedTezosToolkit)
expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n')) expect(consoleSpy).toHaveBeenCalledWith(chalk.bgRedBright('\nChoix invalide\n'))
}); })
}) })
}); })
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment