Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
2.0 KiB

  1. import { describe, it, expect, vi, beforeAll } from 'vitest';
  2. import { createCli } from '../src/cli';
  3. import { addCommands } from '../src/commands';
  4. import { AdderServiceImpl, InvalidArgumentTypeError, ArgumentOutOfRangeError } from '../src/modules/adder';
  5. import { Cli } from '../src/packages/cli-wrapper';
  6. vi.mock('process');
  7. describe('blah', () => {
  8. let cli: Cli;
  9. beforeAll(() => {
  10. cli = createCli({
  11. name: 'cli-test',
  12. logger: false,
  13. });
  14. addCommands(cli);
  15. });
  16. it('returns result when successful', async () => {
  17. const response = await cli.test().run(['add', '1', '2']);
  18. expect(response.exitCode).toBe(0);
  19. });
  20. it('returns error when given invalid inputs', async () => {
  21. vi.spyOn(AdderServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => {
  22. throw new InvalidArgumentTypeError('Invalid input');
  23. });
  24. const response = await cli.test().run(['add', '1', '2']);
  25. expect(response.exitCode).toBe(-1);
  26. });
  27. it('returns error when given out-of-range inputs', async () => {
  28. vi.spyOn(AdderServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => {
  29. throw new ArgumentOutOfRangeError('Out of range');
  30. });
  31. const response = await cli.test().run(['add', '1', '2']);
  32. expect(response.exitCode).toBe(-2);
  33. });
  34. it('returns error when an unexpected error occurs', async () => {
  35. vi.spyOn(AdderServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => {
  36. throw new Error('Unexpected error');
  37. });
  38. const response = await cli.test().run(['add', '1', '2']);
  39. expect(response.exitCode).toBe(-3);
  40. });
  41. it('returns error when given insufficient arguments', async () => {
  42. const response = await cli.test().run(['add', '1']);
  43. expect(response.exitCode).toBe(-1);
  44. });
  45. describe('on interactive mode', () => {
  46. it('prompts values for insufficient arguments', async () => {
  47. const response = await cli
  48. .test()
  49. .promptValue({
  50. a: '1',
  51. b: '2',
  52. })
  53. .run(['add', '-i']);
  54. expect(response.exitCode).not.toBe(-1);
  55. });
  56. });
  57. });