-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from storyblok/bugfix/replace-netrc-with-json
feat: replace netrc with json
- Loading branch information
Showing
12 changed files
with
281 additions
and
518 deletions.
There are no files selected for viewing
This file contains 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 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 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,28 +1,60 @@ | ||
import { isAuthorized, removeAllNetrcEntries } from '../../creds' | ||
import { logoutCommand } from './' | ||
import { session } from '../../session' | ||
|
||
import { removeAllCredentials } from '../../creds' | ||
|
||
vi.mock('../../creds', () => ({ | ||
isAuthorized: vi.fn(), | ||
removeNetrcEntry: vi.fn(), | ||
removeAllNetrcEntries: vi.fn(), | ||
getCredentials: vi.fn(), | ||
addCredentials: vi.fn(), | ||
removeCredentials: vi.fn(), | ||
removeAllCredentials: vi.fn(), | ||
})) | ||
|
||
// Mocking the session module | ||
vi.mock('../../session', () => { | ||
let _cache: Record<string, any> | null = null | ||
const session = () => { | ||
if (!_cache) { | ||
_cache = { | ||
state: { | ||
isLoggedIn: true, | ||
password: 'valid-token', | ||
region: 'eu', | ||
}, | ||
updateSession: vi.fn(), | ||
persistCredentials: vi.fn(), | ||
initializeSession: vi.fn(), | ||
} | ||
} | ||
return _cache | ||
} | ||
|
||
return { | ||
session, | ||
} | ||
}) | ||
|
||
describe('logoutCommand', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('should log out the user if has previously login', async () => { | ||
vi.mocked(isAuthorized).mockResolvedValue(true) | ||
|
||
session().state = { | ||
isLoggedIn: true, | ||
password: 'valid-token', | ||
region: 'eu', | ||
} | ||
await logoutCommand.parseAsync(['node', 'test']) | ||
expect(removeAllNetrcEntries).toHaveBeenCalled() | ||
expect(removeAllCredentials).toHaveBeenCalled() | ||
}) | ||
|
||
it('should not log out the user if has not previously login', async () => { | ||
vi.mocked(isAuthorized).mockResolvedValue(false) | ||
session().state = { | ||
isLoggedIn: false, | ||
} | ||
await logoutCommand.parseAsync(['node', 'test']) | ||
expect(removeAllNetrcEntries).not.toHaveBeenCalled() | ||
expect(removeAllCredentials).not.toHaveBeenCalled() | ||
}) | ||
}) |
This file contains 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 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
Oops, something went wrong.