|
| 1 | +import { it, expect, vi, describe, beforeEach } from "vitest"; |
| 2 | +import inquirer from "inquirer"; |
| 3 | +import fs from "fs"; |
| 4 | +import { askForTransactionLogPath } from "../../setup"; |
| 5 | + |
| 6 | +/* |
| 7 | + Test Case 1: |
| 8 | + Description: function askForSuperAdminEmail should return email as entered. |
| 9 | + Expected Behavior: When the askForSuperAdminEmail function is called, it should prompt the user to enter an email address, and upon entering, it should return the entered email address. |
| 10 | +
|
| 11 | + Test Case 2: |
| 12 | + Description: superAdmin prompts user, updates .env_test, and does not throw errors. |
| 13 | + Expected Behavior: When the superAdmin function is called, it should prompt the user to enter an email address for the last resort super admin, update the .env_test file with the entered email address, and it should not throw any errors during execution. |
| 14 | +
|
| 15 | + Note: Each test case involves mocking user input using inquirer, executing the relevant function, and asserting the expected behavior by checking the returned email or the updated .env_test file. |
| 16 | +*/ |
| 17 | +describe("Setup -> transactionLogPath", () => { |
| 18 | + beforeEach(() => { |
| 19 | + vi.clearAllMocks(); |
| 20 | + }); |
| 21 | + |
| 22 | + it("should return the transaction log path as entered by the user", async () => { |
| 23 | + const currDir = process.cwd(); |
| 24 | + const testPath = `${currDir}/tests/setup/test-transaction.log`; |
| 25 | + vi.spyOn(inquirer, "prompt").mockResolvedValueOnce({ logpath: testPath }); |
| 26 | + vi.spyOn(fs, "existsSync").mockReturnValueOnce(true); |
| 27 | + vi.spyOn(fs, "accessSync").mockReturnValueOnce(undefined); |
| 28 | + |
| 29 | + const result = await askForTransactionLogPath(); |
| 30 | + expect(result).toEqual(testPath); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should handle invalid path and prompt user again", async () => { |
| 34 | + const currDir = process.cwd(); |
| 35 | + const testPath = `${currDir}/tests/setup/test-transaction.log`; |
| 36 | + vi.spyOn(inquirer, "prompt") |
| 37 | + .mockResolvedValueOnce({ logpath: "invalidpath" }) |
| 38 | + .mockResolvedValueOnce({ logpath: testPath }); |
| 39 | + vi.spyOn(fs, "existsSync") |
| 40 | + .mockReturnValueOnce(false) |
| 41 | + .mockReturnValueOnce(true); |
| 42 | + vi.spyOn(fs, "accessSync").mockReturnValueOnce(undefined); |
| 43 | + const result = await askForTransactionLogPath(); |
| 44 | + expect(result).toEqual(testPath); |
| 45 | + }); |
| 46 | +}); |
0 commit comments