|
| 1 | +/* |
| 2 | + * @bitkidd/adonis-credentials |
| 3 | + * |
| 4 | + * (c) Chirill Ceban <cc@bitkidd.dev> |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +import 'reflect-metadata' |
| 11 | + |
| 12 | +import test from 'japa' |
| 13 | +import { Kernel } from '@adonisjs/core/build/standalone' |
| 14 | +import { ApplicationContract } from '@ioc:Adonis/Core/Application' |
| 15 | + |
| 16 | +import CredentialsCreate from '../commands/CredentialsCreate' |
| 17 | +import CredentialsPipe from '../commands/CredentialsPipe' |
| 18 | +import { fs, setupApplication } from '../test-helpers' |
| 19 | + |
| 20 | +let app: ApplicationContract |
| 21 | + |
| 22 | +test.group('Command - Credentials Pipe', (group) => { |
| 23 | + group.beforeEach(async () => { |
| 24 | + app = await setupApplication() |
| 25 | + const command = new CredentialsCreate(app, new Kernel(app)) |
| 26 | + await command.run() |
| 27 | + }) |
| 28 | + |
| 29 | + group.afterEach(async () => { |
| 30 | + await fs.cleanup() |
| 31 | + }) |
| 32 | + |
| 33 | + test('should throw an error when credentials key file does not exist', async (assert) => { |
| 34 | + await fs.remove('resources/credentials/test.key') |
| 35 | + |
| 36 | + const command = new CredentialsPipe(app, new Kernel(app)) |
| 37 | + command.command = `echo 'test';` |
| 38 | + await command.run() |
| 39 | + |
| 40 | + assert.deepStrictEqual( |
| 41 | + command.ui.testingRenderer.logs.map((log) => ({ |
| 42 | + ...log, |
| 43 | + message: log.message.replace(/(\[.*?\])/g, '').trim(), |
| 44 | + })), |
| 45 | + [ |
| 46 | + { |
| 47 | + stream: 'stderr', |
| 48 | + message: `Credentials key file for 'test' environment does not exist`, |
| 49 | + }, |
| 50 | + ] |
| 51 | + ) |
| 52 | + }) |
| 53 | + |
| 54 | + test('should throw an error when credentials file does not exist', async (assert) => { |
| 55 | + await fs.remove('resources/credentials/test.credentials') |
| 56 | + |
| 57 | + const command = new CredentialsPipe(app, new Kernel(app)) |
| 58 | + command.command = `echo 'test';` |
| 59 | + await command.run() |
| 60 | + |
| 61 | + assert.deepStrictEqual( |
| 62 | + command.ui.testingRenderer.logs.map((log) => ({ |
| 63 | + ...log, |
| 64 | + message: log.message.replace(/(\[.*?\])/g, '').trim(), |
| 65 | + })), |
| 66 | + [ |
| 67 | + { |
| 68 | + stream: 'stderr', |
| 69 | + message: `Credentials file for 'test' environment does not exist`, |
| 70 | + }, |
| 71 | + ] |
| 72 | + ) |
| 73 | + }) |
| 74 | +}) |
0 commit comments