Skip to content

Commit

Permalink
[bulk] Publishing a single un-previewed resource with bulk selection …
Browse files Browse the repository at this point in the history
…fires an error (#696)

* fix: handle 404 for single entry bulk publish

* chore: corresponding test

* chore: simplify changes

* chore: not only
  • Loading branch information
kptdobe authored Mar 22, 2024
1 parent 47b5cf5 commit 1ace733
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/extension/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,7 @@ import sampleRUM from './rum.js';
}
try {
if (paths.length === 1) {
let level = 0;
// single operation
const [path] = paths;
const url = getAdminUrl(config, route, path);
Expand All @@ -1845,7 +1846,12 @@ import sampleRUM from './rum.js';
method,
});
if (!resp.ok) {
throw new Error(resp.headers['x-error']);
if (resp.status === 404 && operation === 'publish') {
level = 1;
throw new Error(getBulkText([1], 'result', operation, 'error_no_source'));
} else {
throw new Error(resp.headers['x-error']);
}
} else {
showBulkOperationSummary({
operation,
Expand All @@ -1854,13 +1860,17 @@ import sampleRUM from './rum.js';
});
}
} catch (e) {
console.error(`bulk ${operation} failed: ${e.message}`);
if (level > 0) {
console.warn(`bulk ${operation} failed: ${e.message}`);
} else {
console.error(`bulk ${operation} failed: ${e.message}`);
}
sk.showModal({
message: [
getBulkText([1], 'result', operation, 'failure'),
e.message || i18n(sk, 'bulk_error'),
],
level: 0,
level,
sticky: true,
});
}
Expand Down
39 changes: 39 additions & 0 deletions test/bulk-publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SidekickTest } from './SidekickTest.js';

const SHAREPOINT_FIXTURE = 'admin-sharepoint.html';
const GDRIVE_FIXTURE = 'admin-gdrive.html';

const TESTS = [{
env: 'sharepoint',
setup: new Setup('blog'),
Expand Down Expand Up @@ -225,6 +226,44 @@ describe('Test bulk publish plugin', () => {
assert.strictEqual(clipboardText.split('\n').length, 3, `3 URLs not copied to clipboard in ${env}: \n${clipboardText}`);
assert.strictEqual(openedWindows.length, 3, `3 URLs not opened in ${env}: \n${openedWindows.join('\n')}`);
}).timeout(IT_DEFAULT_TIMEOUT);

it(`Bulk publish plugin tells users to preview first in ${env} (single selection)`, async () => {
nock.sidekick(setup);
nock.admin(setup, {
route: 'status',
type: 'admin',
persist: true,
});
nock.admin(setup, {
route: 'live',
method: 'post',
status: [404],
});
const { notification } = await new SidekickTest({
browser,
page,
fixture,
sidekickConfig: setup.sidekickConfig,
configJson: setup.configJson,
url: setup.getUrl('edit', 'admin'),
plugin: 'bulk-publish',
pluginSleep: 5000,
loadModule: true,
acceptDialogs: true,
pre: (p) => p.evaluate(() => {
// user deselects one, keep one
document.getElementById('file-pdf').click();
}),
}).run();
assert.ok(
notification?.message.endsWith('File must be previewed first'),
'Inform user to preview first',
);
assert.ok(
notification.className.includes('level-1'),
'Dialog should only be a warning',
);
}).timeout(IT_DEFAULT_TIMEOUT);
});

it('Bulk publish plugin previews single selection without creating a job', async () => {
Expand Down

0 comments on commit 1ace733

Please sign in to comment.