-
Notifications
You must be signed in to change notification settings - Fork 44
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
test: more enhancements #1190
Merged
Merged
test: more enhancements #1190
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
276eeeb
test(openapi/validate): rewrite tests to be more comprehensive
kanadgupta 4376016
chore: prettier
kanadgupta d2c6c7d
chore: remove `expect.assertions` calls
kanadgupta 0a9c737
test: convert
kanadgupta 823a4f9
Merge branch 'next' into kanad-2025-03-05/more-test-migrations
kanadgupta e732458
chore: redo convert again
kanadgupta e175790
test: inspect
kanadgupta 57efb58
chore: slight rework of how we deconstruct result
kanadgupta a7b77fb
docs: deprecate
kanadgupta e15f7d7
test: reduce
kanadgupta 79f23bb
test: login
kanadgupta 5298d38
test: logout
kanadgupta e2d7e26
test: whoami
kanadgupta 759f6d3
chore: lint
kanadgupta a4b4a5f
Merge branch 'next' into kanad-2025-03-05/more-test-migrations
kanadgupta 2a9e39a
test: snaps
kanadgupta 1d84be4
Merge branch 'next' into kanad-2025-03-05/more-test-migrations
kanadgupta da6b188
chore: bad merge oops
kanadgupta 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 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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`rdme login > should bypass prompts and post to /login on the API if passing in every opt (no 2FA) 1`] = ` | ||
{ | ||
"result": "Successfully logged in as [email protected] to the subdomain project.", | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme login > should bypass prompts and post to /login on the API if passing in every opt 1`] = ` | ||
{ | ||
"result": "Successfully logged in as [email protected] to the subdomain project.", | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme login > should error if email is invalid 1`] = ` | ||
{ | ||
"error": [Error: You must provide a valid email address.], | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme login > should error if invalid credentials are given 1`] = ` | ||
{ | ||
"error": [APIv1Error: Either your email address or password is incorrect | ||
|
||
If you need help, email [email protected] and mention log "fake-metrics-uuid".], | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme login > should error if no project provided 1`] = ` | ||
{ | ||
"error": [Error: No project subdomain provided. Please use \`--project\`.], | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme login > should error if trying to access a project that is not yours 1`] = ` | ||
{ | ||
"error": [APIv1Error: The project (unauthorized-project) can't be found. | ||
|
||
If you need help, email [email protected]], | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme login > should make additional prompt for token if login requires 2FA 1`] = ` | ||
{ | ||
"result": "Successfully logged in as [email protected] to the subdomain project.", | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme login > should post to /login on the API 1`] = ` | ||
{ | ||
"result": "Successfully logged in as [email protected] to the subdomain project.", | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme login > should post to /login on the API if passing in project via opt 1`] = ` | ||
{ | ||
"result": "Successfully logged in as [email protected] to the subdomain project.", | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`rdme logout > should log the user out 1`] = ` | ||
{ | ||
"result": "You have logged out of ReadMe. Please use \`rdme login\` to login again.", | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme logout > should report the user as logged out if they aren't logged in 1`] = ` | ||
{ | ||
"result": "You have logged out of ReadMe. Please use \`rdme login\` to login again.", | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`rdme whoami > should error if user is not authenticated 1`] = ` | ||
{ | ||
"error": [Error: Please login using \`rdme login\`.], | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme whoami > should return the authenticated user 1`] = ` | ||
{ | ||
"result": "You are currently logged in as [email protected] to the subdomain project.", | ||
"stderr": "", | ||
"stdout": "", | ||
} | ||
`; |
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 |
---|---|---|
|
@@ -2,10 +2,9 @@ import prompts from 'prompts'; | |
import { describe, beforeAll, afterEach, it, expect } from 'vitest'; | ||
|
||
import Command from '../../src/commands/login.js'; | ||
import { APIv1Error } from '../../src/lib/apiError.js'; | ||
import configStore from '../../src/lib/configstore.js'; | ||
import { getAPIv1Mock } from '../helpers/get-api-mock.js'; | ||
import { runCommandAndReturnResult } from '../helpers/oclif.js'; | ||
import { runCommand, type OclifOutput } from '../helpers/oclif.js'; | ||
|
||
const apiKey = 'abcdefg'; | ||
const email = '[email protected]'; | ||
|
@@ -14,30 +13,30 @@ const project = 'subdomain'; | |
const token = '123456'; | ||
|
||
describe('rdme login', () => { | ||
let run: (args?: string[]) => Promise<string>; | ||
let run: (args?: string[]) => OclifOutput; | ||
|
||
beforeAll(() => { | ||
run = runCommandAndReturnResult(Command); | ||
run = runCommand(Command); | ||
}); | ||
|
||
afterEach(() => configStore.clear()); | ||
|
||
it('should error if no project provided', () => { | ||
prompts.inject([email, password]); | ||
return expect(run()).rejects.toStrictEqual(new Error('No project subdomain provided. Please use `--project`.')); | ||
return expect(run()).resolves.toMatchSnapshot(); | ||
}); | ||
|
||
it('should error if email is invalid', () => { | ||
prompts.inject(['this-is-not-an-email', password, project]); | ||
return expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); | ||
return expect(run()).resolves.toMatchSnapshot(); | ||
}); | ||
|
||
it('should post to /login on the API', async () => { | ||
prompts.inject([email, password, project]); | ||
|
||
const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); | ||
|
||
await expect(run()).resolves.toBe('Successfully logged in as [email protected] to the subdomain project.'); | ||
await expect(run()).resolves.toMatchSnapshot(); | ||
|
||
mock.done(); | ||
|
||
|
@@ -51,9 +50,7 @@ describe('rdme login', () => { | |
|
||
const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); | ||
|
||
await expect(run(['--project', project])).resolves.toBe( | ||
'Successfully logged in as [email protected] to the subdomain project.', | ||
); | ||
await expect(run(['--project', project])).resolves.toMatchSnapshot(); | ||
|
||
mock.done(); | ||
|
||
|
@@ -65,9 +62,9 @@ describe('rdme login', () => { | |
it('should bypass prompts and post to /login on the API if passing in every opt', async () => { | ||
const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project, token }).reply(200, { apiKey }); | ||
|
||
await expect(run(['--email', email, '--password', password, '--project', project, '--otp', token])).resolves.toBe( | ||
'Successfully logged in as [email protected] to the subdomain project.', | ||
); | ||
await expect( | ||
run(['--email', email, '--password', password, '--project', project, '--otp', token]), | ||
).resolves.toMatchSnapshot(); | ||
|
||
mock.done(); | ||
|
||
|
@@ -79,9 +76,7 @@ describe('rdme login', () => { | |
it('should bypass prompts and post to /login on the API if passing in every opt (no 2FA)', async () => { | ||
const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); | ||
|
||
await expect(run(['--email', email, '--password', password, '--project', project])).resolves.toBe( | ||
'Successfully logged in as [email protected] to the subdomain project.', | ||
); | ||
await expect(run(['--email', email, '--password', password, '--project', project])).resolves.toMatchSnapshot(); | ||
|
||
mock.done(); | ||
|
||
|
@@ -101,7 +96,7 @@ describe('rdme login', () => { | |
|
||
const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(401, errorResponse); | ||
|
||
await expect(run()).rejects.toStrictEqual(new APIv1Error(errorResponse)); | ||
await expect(run()).resolves.toMatchSnapshot(); | ||
|
||
mock.done(); | ||
}); | ||
|
@@ -121,7 +116,7 @@ describe('rdme login', () => { | |
.post('/api/v1/login', { email, password, project, token }) | ||
.reply(200, { apiKey }); | ||
|
||
await expect(run()).resolves.toBe('Successfully logged in as [email protected] to the subdomain project.'); | ||
await expect(run()).resolves.toMatchSnapshot(); | ||
|
||
mock.done(); | ||
|
||
|
@@ -144,7 +139,7 @@ describe('rdme login', () => { | |
.post('/api/v1/login', { email, password, project: projectThatIsNotYours }) | ||
.reply(404, errorResponse); | ||
|
||
await expect(run()).rejects.toStrictEqual(new APIv1Error(errorResponse)); | ||
await expect(run()).resolves.toMatchSnapshot(); | ||
|
||
mock.done(); | ||
}); | ||
|
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,15 +1,14 @@ | ||
import { describe, afterEach, beforeAll, it, expect } from 'vitest'; | ||
|
||
import pkg from '../../package.json' with { type: 'json' }; | ||
import Command from '../../src/commands/logout.js'; | ||
import configStore from '../../src/lib/configstore.js'; | ||
import { runCommandAndReturnResult } from '../helpers/oclif.js'; | ||
import { runCommand, type OclifOutput } from '../helpers/oclif.js'; | ||
|
||
describe('rdme logout', () => { | ||
let run: (args?: string[]) => Promise<string>; | ||
let run: (args?: string[]) => OclifOutput; | ||
|
||
beforeAll(() => { | ||
run = runCommandAndReturnResult(Command); | ||
run = runCommand(Command); | ||
}); | ||
|
||
afterEach(() => { | ||
|
@@ -20,18 +19,14 @@ describe('rdme logout', () => { | |
configStore.delete('email'); | ||
configStore.delete('project'); | ||
|
||
return expect(run()).resolves.toBe( | ||
`You have logged out of ReadMe. Please use \`${pkg.name} login\` to login again.`, | ||
); | ||
return expect(run()).resolves.toMatchSnapshot(); | ||
}); | ||
|
||
it('should log the user out', async () => { | ||
configStore.set('email', '[email protected]'); | ||
configStore.set('project', 'subdomain'); | ||
|
||
await expect(run()).resolves.toBe( | ||
`You have logged out of ReadMe. Please use \`${pkg.name} login\` to login again.`, | ||
); | ||
await expect(run()).resolves.toMatchSnapshot(); | ||
|
||
expect(configStore.get('email')).toBeUndefined(); | ||
expect(configStore.get('project')).toBeUndefined(); | ||
|
30 changes: 30 additions & 0 deletions
30
__tests__/commands/openapi/__snapshots__/convert.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`rdme openapi convert > error handling > should warn if given an OpenAPI 3.0 definition (format: json) 1`] = ` | ||
{ | ||
"result": "Your API definition has been converted and bundled and saved to output.json!", | ||
"stderr": "- Validating the API definition located at petstore.json... | ||
⚠️ Warning! The input file is already OpenAPI, so no conversion is necessary. Any external references will be bundled. | ||
", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme openapi convert > error handling > should warn if given an OpenAPI 3.0 definition (format: yaml) 1`] = ` | ||
{ | ||
"result": "Your API definition has been converted and bundled and saved to output.json!", | ||
"stderr": "- Validating the API definition located at petstore.yaml... | ||
⚠️ Warning! The input file is already OpenAPI, so no conversion is necessary. Any external references will be bundled. | ||
", | ||
"stdout": "", | ||
} | ||
`; | ||
|
||
exports[`rdme openapi convert > should convert with no prompts via opts 1`] = ` | ||
{ | ||
"result": "Your API definition has been converted and bundled and saved to output.json!", | ||
"stderr": "- Validating the API definition located at petstore-simple.json... | ||
", | ||
"stdout": "", | ||
} | ||
`; |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SoftError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:were-all-trying-to-find-the-guy-who-did-this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
he got me. that f***ing kanad gupta boomed me.