|
| 1 | +import { SecretsAddCommand } from '../../../../src/commands/secrets/add.js'; |
| 2 | +import { SecretsLsCommand } from '../../../../src/commands/secrets/ls.js'; |
| 3 | +import { SecretsRmCommand } from '../../../../src/commands/secrets/rm.js'; |
| 4 | +import { testRunCommand } from '../../../../src/lib/command-framework/apify-command.js'; |
| 5 | +import { getSecretsFile } from '../../../../src/lib/secrets.js'; |
| 6 | + |
| 7 | +const SECRET_KEY_1 = 'testSecret1'; |
| 8 | +const SECRET_KEY_2 = 'testSecret2'; |
| 9 | +const SECRET_VALUE = 'testSecretValue'; |
| 10 | + |
| 11 | +describe('apify secrets ls', () => { |
| 12 | + beforeAll(async () => { |
| 13 | + // Clean up any existing test secrets |
| 14 | + const secrets = getSecretsFile(); |
| 15 | + if (secrets[SECRET_KEY_1]) { |
| 16 | + await testRunCommand(SecretsRmCommand, { |
| 17 | + args_name: SECRET_KEY_1, |
| 18 | + }); |
| 19 | + } |
| 20 | + if (secrets[SECRET_KEY_2]) { |
| 21 | + await testRunCommand(SecretsRmCommand, { |
| 22 | + args_name: SECRET_KEY_2, |
| 23 | + }); |
| 24 | + } |
| 25 | + |
| 26 | + // Add test secrets |
| 27 | + await testRunCommand(SecretsAddCommand, { |
| 28 | + args_name: SECRET_KEY_1, |
| 29 | + args_value: SECRET_VALUE, |
| 30 | + }); |
| 31 | + await testRunCommand(SecretsAddCommand, { |
| 32 | + args_name: SECRET_KEY_2, |
| 33 | + args_value: SECRET_VALUE, |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should list all secrets', async () => { |
| 38 | + const spy = vitest.spyOn(console, 'log'); |
| 39 | + |
| 40 | + await testRunCommand(SecretsLsCommand, {}); |
| 41 | + |
| 42 | + // Verify the command outputs our test secrets |
| 43 | + const output = spy.mock.calls.map((call) => call.join(' ')).join('\n'); |
| 44 | + expect(output).to.include(SECRET_KEY_1); |
| 45 | + expect(output).to.include(SECRET_KEY_2); |
| 46 | + |
| 47 | + spy.mockRestore(); |
| 48 | + }); |
| 49 | + |
| 50 | + afterAll(async () => { |
| 51 | + // Clean up test secrets |
| 52 | + const secrets = getSecretsFile(); |
| 53 | + if (secrets[SECRET_KEY_1]) { |
| 54 | + await testRunCommand(SecretsRmCommand, { |
| 55 | + args_name: SECRET_KEY_1, |
| 56 | + }); |
| 57 | + } |
| 58 | + if (secrets[SECRET_KEY_2]) { |
| 59 | + await testRunCommand(SecretsRmCommand, { |
| 60 | + args_name: SECRET_KEY_2, |
| 61 | + }); |
| 62 | + } |
| 63 | + }); |
| 64 | +}); |
0 commit comments