Skip to content
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

fix: Fix bulk action in search command #528

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ class SearchCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(SearchCommand);

if (flags.all && flags.limit) {
throw new BoxCLIError('--all and --limit flags cannot be used together.');
if (flags.all && (flags.limit || flags['max-items'])) {
throw new BoxCLIError('--all and --limit(--max-items) flags cannot be used together.');
}

if (!flags.all) {
if (flags.limit && flags['max-items'] && flags.limit !== flags['max-items']) {
throw new BoxCLIError(' --limit and --max-items flags cannot be used together.');
}

if (!flags.all && !flags['max-items']) {
flags['max-items'] = flags.limit || RESULTS_LIMIT;
this.flags['max-items'] = flags['max-items'];
}
Expand Down Expand Up @@ -289,6 +293,10 @@ SearchCommand.flags = {
limit: flags.integer({
description: 'Defines the maximum number of items to return. Default value is 100.',
}),
'max-items': flags.integer({
description: 'A value that indicates the maximum number of results to return.',
hidden: true
}),
all: flags.boolean({
description: 'Returns all search results.',
}),
Expand Down
62 changes: 59 additions & 3 deletions test/commands/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const { test } = require('@oclif/test');
const { assert } = require('chai');
const { getFixture, TEST_API_ROOT } = require('../helpers/test-helper');
const leche = require('leche');

const os = require('os');
const path = require('path');
describe('Search', () => {

let query = 'Test',
bulkInputFilePath = path.join(__dirname, '../fixtures/search/bulk/bulk_get_search_query_input.csv'),
fixture = getFixture('search/get_search_query_page_1'),
fixture2 = getFixture('search/get_search_query_page_2'),
jsonOutput = getFixture('output/search_json.txt'),
Expand Down Expand Up @@ -365,7 +367,61 @@ describe('Search', () => {
.it('should return limited results when --limit flag provided', ctx => {
assert.equal(ctx.stdout, jsonOutputLimitedTo5);
});

test
.nock(TEST_API_ROOT, api => api
.get('/2.0/search')
.query({
query,
limit: 5
})
.reply(200, fixture)
)
.stdout()
.command([
'search',
query,
'--json',
'--max-items=5',
'--token=test'
])
.it('should return same limited results when --max-items flag provided instead of --limit', ctx => {
assert.equal(ctx.stdout, jsonOutputLimitedTo5);
});
});
describe('bulk', () => {
test
.nock(TEST_API_ROOT, api => api
.get('/2.0/search')
.query({
limit: 100,
query: '',
scope: 'enterprise_content',
type: 'file'
})
.reply(200, { entries: [] })
.get('/2.0/search')
.query({
limit: 100,
query: '',
scope: 'enterprise_content',
type: 'folder',
})
.reply(200, { entries: [] })
)
.stdout()
.stderr()
.command([
'search',
`--bulk-file-path=${bulkInputFilePath}`,
'--json',
'--token=test'
])
.it('should make a successful search call for each entry in a bulk file', ctx => {
let expectedMessage = `All bulk input entries processed successfully.${os.EOL}`;
assert.equal(ctx.stderr, expectedMessage);
});
});
describe('fails', () => {
test
.stderr()
Expand All @@ -377,7 +433,7 @@ describe('Search', () => {
'--token=test'
])
.it('when both --all and --limit flag provided', ctx => {
assert.include(ctx.stderr, '--all and --limit flags cannot be used together.');
assert.include(ctx.stderr, '--all and --limit(--max-items) flags cannot be used together.');
});
});
});
});
3 changes: 3 additions & 0 deletions test/fixtures/search/bulk/bulk_get_search_query_input.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scope,type
enterprise_content,file
enterprise_content,folder
Loading