Skip to content

fix: ignore mapped metadata sheet with not default #678

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

Merged
merged 1 commit into from
Sep 4, 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
6 changes: 5 additions & 1 deletion src/steps/fetch-mapped-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ export default async function fetchMappedMetadata(state) {
} catch (e) {
throw new PipelineStatusError(500, `failed parsing of ${metadataPath}: ${e.message}`);
}

const { data } = json.default ?? json;
if (!data) {
state.log.info(`default sheet missing in ${metadataPath}`);
return;
}

if (!Array.isArray(data)) {
throw new PipelineStatusError(500, `failed loading of ${metadataPath}: data must be an array`);
}
Expand Down
25 changes: 23 additions & 2 deletions test/steps/fetch-mapped-metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PipelineStatusError } from '../../src/index.js';
import { StaticS3Loader } from '../StaticS3Loader.js';
import fetchMappedMetadata from '../../src/steps/fetch-mapped-metadata.js';
import { FileS3Loader } from '../FileS3Loader.js';
import { Modifiers } from '../../src/utils/modifiers.js';

describe('Fetch Mapped Metadata', () => {
it('parses KV sheet', async () => {
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('Fetch Mapped Metadata', () => {
await assert.rejects(promise, new PipelineStatusError(500, 'failed parsing of /mapped/metadata.json: Unexpected token \'h\', "this is no json!" is not valid JSON'));
});

it('throws error on metadata with no data array', async () => {
it('throws error on metadata with invalid data array', async () => {
const promise = fetchMappedMetadata({
log: console,
contentBusId: 'foo-id',
Expand All @@ -68,13 +69,33 @@ describe('Fetch Mapped Metadata', () => {
s3Loader: new StaticS3Loader()
.reply('helix-content-bus', 'foo-id/live/mapped/metadata.json', {
status: 200,
body: '{}',
body: '{ "data": "42" }',
headers: new Map(),
}),
});
await assert.rejects(promise, new PipelineStatusError(500, 'failed loading of /mapped/metadata.json: data must be an array'));
});

it('ignores metadata with no data array', async () => {
const state = {
log: console,
contentBusId: 'foo-id',
partition: 'live',
mapped: true,
info: {
path: '/mapped',
},
s3Loader: new StaticS3Loader()
.reply('helix-content-bus', 'foo-id/live/mapped/metadata.json', {
status: 200,
body: '{}',
headers: new Map(),
}),
};
await fetchMappedMetadata(state);
assert.strictEqual(state.mappedMetadata, Modifiers.EMPTY);
});

it('throws error on generic error', async () => {
const promise = fetchMappedMetadata({
log: console,
Expand Down
Loading