-
Notifications
You must be signed in to change notification settings - Fork 16
Fix/dx 3020 cli auth test cases and workflow update #2011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
878ec32
update auth test cases
harshithad0703 d994cba
fix: Add type annotations to test stubs for better type safety
harshithad0703 fabd63a
fix: Update test lifecycle hooks to use beforeEach and afterEach for …
harshithad0703 1aca059
refactor: Reorganize logout command tests for clarity and consistency
harshithad0703 ecc8ead
feat: Add Contentstack Auth plugin inunit tests workflow
harshithad0703 50e84bc
test: Enhance auth:tokens:remove tests for better coverage and error …
harshithad0703 4c770fb
update auth:tokens:remove tests
harshithad0703 80e8d24
update auth test
harshithad0703 50660e2
refactor: Update ESLint rules for TypeScript to disable quotes and ty…
harshithad0703 e732144
Merge branch 'development' into fix/dx-3020-cli-auth-test-cases
harshithad0703 4bd9ae4
test: Update auth test assertions for login and error handling
harshithad0703 4a88f4a
test: Enhance token management tests with additional configurations a…
harshithad0703 608cf32
refactor: Disable ban-types rule in ESLint configuration for TypeScript
harshithad0703 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 26 additions & 25 deletions
51
packages/contentstack-auth/test/unit/commands/logout.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,45 @@ | ||
| import { expect } from 'chai'; | ||
| import * as sinon from 'sinon'; | ||
| import LogoutCommand from '../../../src/commands/auth/logout'; | ||
| import { cliux } from '@contentstack/cli-utilities'; | ||
| import { authHandler } from '../../../src/utils'; | ||
| import { CLIError, cliux } from '@contentstack/cli-utilities'; | ||
|
|
||
| const user = { email: '***REMOVED***', authtoken: 'testtoken' }; | ||
| const validAuthToken = 'bltadjkjdkjfd'; | ||
|
|
||
| describe('Logout Command', () => { | ||
| let logoutStub; | ||
| let inquireStub; | ||
| let successStub; | ||
| before(function () { | ||
| logoutStub = sinon.stub(authHandler, 'logout').callsFake(function (authToken): Promise<any> { | ||
| if (authToken === validAuthToken) { | ||
| return Promise.resolve({ user }); | ||
| } | ||
| return Promise.reject(new CLIError({ message: 'invalid token' })); | ||
| }); | ||
| let inquireStub: sinon.SinonStub; | ||
| let successStub: sinon.SinonStub; | ||
| let loaderStub: sinon.SinonStub; | ||
| let logoutStub: sinon.SinonStub; | ||
| let isAuthenticatedStub: sinon.SinonStub; | ||
| let configStub: sinon.SinonStub; | ||
|
|
||
| inquireStub = sinon.stub(cliux, 'inquire').resolves(true); | ||
| successStub = sinon.stub(cliux, 'success').resolves(); | ||
| beforeEach(() => { | ||
| inquireStub = sinon.stub(cliux, 'inquire'); | ||
| successStub = sinon.stub(cliux, 'success'); | ||
| loaderStub = sinon.stub(cliux, 'loader'); | ||
| logoutStub = sinon.stub(authHandler, 'logout').resolves({ user: {} }); | ||
| }); | ||
|
|
||
| after(() => { | ||
| logoutStub.restore(); | ||
| afterEach(() => { | ||
| inquireStub.restore(); | ||
| successStub.restore(); | ||
| loaderStub.restore(); | ||
| logoutStub.restore(); | ||
| }); | ||
|
|
||
| it('Logout with valid token, should be successful', async function () { | ||
| await LogoutCommand.run([]); | ||
| expect(inquireStub.calledOnce).to.be.true; | ||
| }); | ||
|
|
||
| it('logout with force flag, should not propmt the confirm', async function () { | ||
| const stub1 = sinon.stub(LogoutCommand.prototype, 'run').resolves(); | ||
| const args = ['-f']; | ||
| await LogoutCommand.run(args); | ||
| expect(stub1.calledOnce).to.be.true; | ||
| stub1.restore(); | ||
| it('Logout should prompt for confirmation', async function () { | ||
| inquireStub.resolves(false); | ||
| await LogoutCommand.run([]); | ||
| expect(inquireStub.calledOnce).to.be.true; | ||
| expect(inquireStub.firstCall.args[0]).to.deep.include({ | ||
| type: 'confirm', | ||
| message: 'CLI_AUTH_LOGOUT_CONFIRM', | ||
| name: 'confirmation' | ||
| }); | ||
| expect(logoutStub.called).to.be.false; // Should not call logout if confirmation is denied | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.