-
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(docs): move --cleanup
option into docs:prune
command
#644
Merged
kanadgupta
merged 9 commits into
main
from
kanad/rm-5598-migrate-docs---cleanup-option-into-a
Oct 27, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb97834
refactor(docs): move cleanup into separate command
kanadgupta 7ba08c7
docs: update
kanadgupta 7f60562
test: fix snapshot
kanadgupta c938229
test: smol cleanup
kanadgupta 863d06c
chore: rename cleanup to prune
kanadgupta 7f6d74a
chore: small naming convention change, lint
kanadgupta c503354
chore: cleanup JSDoc
kanadgupta ac55807
fix: use prompt for every call instead of warning
kanadgupta 07a8dc9
Merge branch 'main' into kanad/rm-5598-migrate-docs---cleanup-option-…
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
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import nock from 'nock'; | ||
import prompts from 'prompts'; | ||
|
||
import DocsPruneCommand from '../../../src/cmds/docs/prune'; | ||
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock'; | ||
|
||
const docsPrune = new DocsPruneCommand(); | ||
|
||
const fixturesBaseDir = '__fixtures__/docs'; | ||
|
||
const key = 'API_KEY'; | ||
const version = '1.0.0'; | ||
|
||
describe('rdme docs:prune', () => { | ||
const folder = `./__tests__/${fixturesBaseDir}/delete-docs`; | ||
|
||
beforeAll(() => nock.disableNetConnect()); | ||
|
||
afterAll(() => nock.cleanAll()); | ||
|
||
it('should prompt for login if no API key provided', async () => { | ||
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(); | ||
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); | ||
await expect(docsPrune.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.')); | ||
consoleInfoSpy.mockRestore(); | ||
}); | ||
|
||
it('should error in CI if no API key provided', async () => { | ||
process.env.TEST_CI = 'true'; | ||
await expect(docsPrune.run({})).rejects.toStrictEqual( | ||
new Error('No project API key provided. Please use `--key`.') | ||
); | ||
delete process.env.TEST_CI; | ||
}); | ||
|
||
it('should error if no folder provided', () => { | ||
return expect(docsPrune.run({ key, version: '1.0.0' })).rejects.toStrictEqual( | ||
new Error('No folder provided. Usage `rdme docs:prune <folder> [options]`.') | ||
); | ||
}); | ||
|
||
it('should error if the argument is not a folder', async () => { | ||
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); | ||
|
||
await expect(docsPrune.run({ key, version: '1.0.0', folder: 'not-a-folder' })).rejects.toThrow( | ||
"ENOENT: no such file or directory, scandir 'not-a-folder'" | ||
); | ||
|
||
versionMock.done(); | ||
}); | ||
|
||
it('should do nothing if the user aborted', async () => { | ||
prompts.inject([false]); | ||
|
||
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); | ||
|
||
await expect( | ||
docsPrune.run({ | ||
folder, | ||
key, | ||
version, | ||
}) | ||
).rejects.toStrictEqual(new Error('Aborting, no changes were made.')); | ||
|
||
versionMock.done(); | ||
}); | ||
|
||
it('should delete doc if file is missing', async () => { | ||
prompts.inject([true]); | ||
|
||
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); | ||
|
||
const apiMocks = getAPIMockWithVersionHeader(version) | ||
.get('/api/v1/categories?perPage=20&page=1') | ||
.basicAuth({ user: key }) | ||
.reply(200, [{ slug: 'category1', type: 'guide' }], { 'x-total-count': '1' }) | ||
.get('/api/v1/categories/category1/docs') | ||
.basicAuth({ user: key }) | ||
.reply(200, [{ slug: 'this-doc-should-be-missing-in-folder' }, { slug: 'some-doc' }]) | ||
.delete('/api/v1/docs/this-doc-should-be-missing-in-folder') | ||
.basicAuth({ user: key }) | ||
.reply(204, ''); | ||
|
||
await expect( | ||
docsPrune.run({ | ||
folder, | ||
key, | ||
version, | ||
}) | ||
).resolves.toBe('🗑️ successfully deleted `this-doc-should-be-missing-in-folder`.'); | ||
|
||
apiMocks.done(); | ||
versionMock.done(); | ||
}); | ||
|
||
it('should return doc delete info for dry run', async () => { | ||
prompts.inject([true]); | ||
|
||
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); | ||
const apiMocks = getAPIMockWithVersionHeader(version) | ||
.get('/api/v1/categories?perPage=20&page=1') | ||
.basicAuth({ user: key }) | ||
.reply(200, [{ slug: 'category1', type: 'guide' }], { 'x-total-count': '1' }) | ||
.get('/api/v1/categories/category1/docs') | ||
.basicAuth({ user: key }) | ||
.reply(200, [{ slug: 'this-doc-should-be-missing-in-folder' }]); | ||
|
||
await expect( | ||
docsPrune.run({ | ||
folder, | ||
key, | ||
version, | ||
dryRun: true, | ||
}) | ||
).resolves.toBe('🎭 dry run! This will delete `this-doc-should-be-missing-in-folder`.'); | ||
|
||
apiMocks.done(); | ||
versionMock.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
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.
Honestly not opposed to deprecating this command now and removing it in v9.
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.
agree, will do in a separate PR!1
edit: see #646
Footnotes
ticketed in RM-5649 ↩