diff --git a/src/commands/auth/login.js b/src/commands/auth/login.js index 08c4db3..f314820 100644 --- a/src/commands/auth/login.js +++ b/src/commands/auth/login.js @@ -36,7 +36,8 @@ class LoginCommand extends ImsBaseCommand { if (flags.ctx === CLI) { await context.setCli({ 'cli.bare-output': flags.bare - }) + }, + !!flags.local) } // now we need to set the client_id because the server diff --git a/test/commands/auth/login.test.js b/test/commands/auth/login.test.js index 81ef904..51a67c9 100644 --- a/test/commands/auth/login.test.js +++ b/test/commands/auth/login.test.js @@ -54,6 +54,46 @@ test('run - success (no flags)', async () => { expect(spy).toHaveBeenCalled() }) +describe('cli context', () => { + test('run success (--local)', async () => { + const tokenData = { data: '' } + ims.getTokenData.mockImplementation(() => tokenData) + + command.argv = ['--ctx', 'cli', '--local'] + const runResult = command.run([]) + + await expect(runResult instanceof Promise).toBeTruthy() + await expect(runResult).resolves.not.toThrow() + expect(ims.context.setCli).toHaveBeenCalledWith(expect.any(Object), true) + }) + + test('run success (--global)', async () => { + const tokenData = { data: '' } + + ims.getTokenData.mockImplementation(() => tokenData) + + command.argv = ['--ctx', 'cli', '--global'] + const runResult = command.run([]) + + await expect(runResult instanceof Promise).toBeTruthy() + await expect(runResult).resolves.not.toThrow() + expect(ims.context.setCli).toHaveBeenCalledWith(expect.any(Object), false) + }) + + test('run success (no flag - should be global as default)', async () => { + const tokenData = { data: '' } + + ims.getTokenData.mockImplementation(() => tokenData) + + command.argv = ['--ctx', 'cli'] + const runResult = command.run([]) + + await expect(runResult instanceof Promise).toBeTruthy() + await expect(runResult).resolves.not.toThrow() + expect(ims.context.setCli).toHaveBeenCalledWith(expect.any(Object), false) + }) +}) + test('run - success (--decode)', async () => { const context = 'my-context' const tokenData = {