-
Notifications
You must be signed in to change notification settings - Fork 43
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
refactor: commands into command classes #424
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
70557ac
fix: quirks with version commands not always handling errors properly
erunion 3d394d6
fix: use the right accessor for getting config data
erunion c6bf6da
refactor: commands into command classes
erunion e0521be
fix: typos
erunion eff1284
fix: we know the name of the login command
erunion aa36dd9
fix: reverting an unnecessary change
erunion ab02e04
fix: pr feedback
erunion 717ed68
Merge branch 'main' into refactor/command-classes
erunion 7b123cd
fix: bring back snapshot
erunion e2c10be
fix: pulling some snapshots that have color in them as they're causin…
erunion 2bd4199
test: tweaks
erunion 517d7ea
fix: removing a dupe color config
erunion 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
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 |
---|---|---|
|
@@ -8,8 +8,11 @@ const frontMatter = require('gray-matter'); | |
|
||
const APIError = require('../../src/lib/apiError'); | ||
|
||
const docs = require('../../src/cmds/docs'); | ||
const docsEdit = require('../../src/cmds/docs/edit'); | ||
const DocsCommand = require('../../src/cmds/docs'); | ||
const DocsEditCommand = require('../../src/cmds/docs/edit'); | ||
|
||
const docs = new DocsCommand(); | ||
const docsEdit = new DocsEditCommand(); | ||
|
||
const fixturesDir = `${__dirname}./../__fixtures__`; | ||
const key = 'API_KEY'; | ||
|
@@ -18,7 +21,7 @@ const category = 'CATEGORY_ID'; | |
const apiSetting = 'API_SETTING_ID'; | ||
|
||
function getNockWithVersionHeader(v) { | ||
return nock(config.host, { | ||
return nock(config.get('host'), { | ||
reqheaders: { | ||
'x-readme-version': v, | ||
}, | ||
|
@@ -105,7 +108,7 @@ describe('rdme docs', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, { category, slug: anotherDoc.slug, body: anotherDoc.doc.content }); | ||
|
||
const versionMock = nock(config.host) | ||
const versionMock = nock(config.get('host')) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
@@ -139,7 +142,7 @@ describe('rdme docs', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, { category, slug: anotherDoc.slug, lastUpdatedHash: anotherDoc.hash }); | ||
|
||
const versionMock = nock(config.host) | ||
const versionMock = nock(config.get('host')) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
@@ -177,7 +180,7 @@ describe('rdme docs', () => { | |
.basicAuth({ user: key }) | ||
.reply(201, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }); | ||
|
||
const versionMock = nock(config.host) | ||
const versionMock = nock(config.get('host')) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
@@ -246,7 +249,7 @@ describe('rdme docs', () => { | |
.basicAuth({ user: key }) | ||
.reply(400, errorObject); | ||
|
||
const versionMock = nock(config.host) | ||
const versionMock = nock(config.get('host')) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
@@ -289,7 +292,7 @@ describe('rdme docs', () => { | |
.basicAuth({ user: key }) | ||
.reply(201, { slug: doc.data.slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }); | ||
|
||
const versionMock = nock(config.host) | ||
const versionMock = nock(config.get('host')) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
@@ -335,7 +338,7 @@ describe('rdme docs:edit', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, { category, slug }); | ||
|
||
const versionMock = nock(config.host) | ||
const versionMock = nock(config.get('host')) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
@@ -367,9 +370,9 @@ describe('rdme docs:edit', () => { | |
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".', | ||
}; | ||
|
||
const getMock = nock(config.host).get(`/api/v1/docs/${slug}`).reply(404, errorObject); | ||
const getMock = nock(config.get('host')).get(`/api/v1/docs/${slug}`).reply(404, errorObject); | ||
|
||
const versionMock = nock(config.host) | ||
const versionMock = nock(config.get('host')) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
@@ -392,11 +395,11 @@ describe('rdme docs:edit', () => { | |
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".', | ||
}; | ||
|
||
const getMock = nock(config.host).get(`/api/v1/docs/${slug}`).reply(200, { body }); | ||
const getMock = nock(config.get('host')).get(`/api/v1/docs/${slug}`).reply(200, { body }); | ||
|
||
const putMock = nock(config.host).put(`/api/v1/docs/${slug}`).reply(400, errorObject); | ||
const putMock = nock(config.get('host')).put(`/api/v1/docs/${slug}`).reply(400, errorObject); | ||
|
||
const versionMock = nock(config.host) | ||
const versionMock = nock(config.get('host')) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
@@ -420,7 +423,7 @@ describe('rdme docs:edit', () => { | |
const slug = 'getting-started'; | ||
const body = 'abcdef'; | ||
|
||
const getMock = nock(config.host) | ||
const getMock = nock(config.get('host')) | ||
.get(`/api/v1/docs/${slug}`) | ||
.reply(200, { body }) | ||
.get(`/api/v1/version/${version}`) | ||
|
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,7 +1,9 @@ | ||
const nock = require('nock'); | ||
const config = require('config'); | ||
const configStore = require('../../src/lib/configstore'); | ||
const cmd = require('../../src/cmds/login'); | ||
const Command = require('../../src/cmds/login'); | ||
|
||
const cmd = new Command(); | ||
|
||
describe('rdme login', () => { | ||
beforeAll(() => nock.disableNetConnect()); | ||
|
@@ -15,28 +17,27 @@ describe('rdme login', () => { | |
}); | ||
|
||
it('should error if email is invalid', () => { | ||
expect.assertions(1); | ||
return expect(cmd.run({ project: 'subdomain', email: 'this-is-not-an-email' })).rejects.toThrow( | ||
'You must provide a valid email address.' | ||
); | ||
}); | ||
|
||
it('should post to /login on the API', () => { | ||
it('should post to /login on the API', async () => { | ||
expect.assertions(3); | ||
const email = '[email protected]'; | ||
const password = '123456'; | ||
const project = 'subdomain'; | ||
const apiKey = 'abcdefg'; | ||
|
||
const mock = nock(config.host).post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); | ||
const mock = nock(config.get('host')).post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); | ||
|
||
return cmd.run({ email, password, project }).then(() => { | ||
mock.done(); | ||
expect(configStore.get('apiKey')).toBe(apiKey); | ||
expect(configStore.get('email')).toBe(email); | ||
expect(configStore.get('project')).toBe(project); | ||
configStore.clear(); | ||
}); | ||
await cmd.run({ email, password, project }); | ||
mock.done(); | ||
|
||
expect(configStore.get('apiKey')).toBe(apiKey); | ||
expect(configStore.get('email')).toBe(email); | ||
expect(configStore.get('project')).toBe(project); | ||
configStore.clear(); | ||
}); | ||
|
||
it('should error if invalid credentials are given', () => { | ||
|
@@ -45,7 +46,7 @@ describe('rdme login', () => { | |
const password = '123456'; | ||
const project = 'subdomain'; | ||
|
||
const mock = nock(config.host).post('/api/v1/login', { email, password, project }).reply(401, { | ||
const mock = nock(config.get('host')).post('/api/v1/login', { email, password, project }).reply(401, { | ||
error: 'LOGIN_INVALID', | ||
message: 'Either your email address or password is incorrect', | ||
suggestion: 'You can reset your password at https://dash.readme.com/forgot', | ||
|
@@ -65,33 +66,32 @@ describe('rdme login', () => { | |
const password = '123456'; | ||
const project = 'subdomain'; | ||
|
||
const mock = nock(config.host).post('/api/v1/login', { email, password, project }).reply(401, { | ||
const mock = nock(config.get('host')).post('/api/v1/login', { email, password, project }).reply(401, { | ||
error: 'LOGIN_TWOFACTOR', | ||
message: 'You must provide a two-factor code', | ||
suggestion: 'You can do it via the API using `token`, or via the CLI using `rdme login --2fa`', | ||
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".', | ||
}); | ||
|
||
return cmd.run({ email, password, project }).catch(err => { | ||
mock.done(); | ||
expect(err.code).toBe('LOGIN_TWOFACTOR'); | ||
expect(err.message).toContain('You must provide a two-factor code'); | ||
mock.done(); | ||
}); | ||
}); | ||
|
||
it('should send 2fa token if provided', () => { | ||
it('should send 2fa token if provided', async () => { | ||
const email = '[email protected]'; | ||
const password = '123456'; | ||
const project = 'subdomain'; | ||
const token = '123456'; | ||
|
||
const mock = nock(config.host) | ||
const mock = nock(config.get('host')) | ||
.post('/api/v1/login', { email, password, project, token }) | ||
.reply(200, { apiKey: '123' }); | ||
|
||
return cmd.run({ email, password, project, token }).then(() => { | ||
mock.done(); | ||
}); | ||
await cmd.run({ email, password, project, token }); | ||
mock.done(); | ||
}); | ||
|
||
it.todo('should error if trying to access a project that is not yours'); | ||
|
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.
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.
Wanna add a small comment explaining why we need this?