Skip to content
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
56 changes: 28 additions & 28 deletions .changeset/ledger.yaml
Original file line number Diff line number Diff line change
@@ -1,124 +1,124 @@
"@tryghost/adapter-base-cache@0.2.0":
'@tryghost/adapter-base-cache@0.2.0':
dir: packages/adapters/cache-base
intents:
- major-areas-fail
- upset-dogs-sort
"@tryghost/adapter-base-scheduling@0.1.1":
'@tryghost/adapter-base-scheduling@0.1.1':
dir: packages/adapters/scheduling-base
intents:
- major-areas-fail
- plain-singers-cheat
"@tryghost/adapter-base-scheduling@0.2.0":
'@tryghost/adapter-base-scheduling@0.2.0':
dir: packages/adapters/scheduling-base
intents:
- fifty-maps-sing
"@tryghost/adapter-base-scheduling@0.2.1":
'@tryghost/adapter-base-scheduling@0.2.1':
dir: packages/adapters/scheduling-base
intents:
- typed-logging-args
"@tryghost/adapter-base-scheduling@0.2.2":
'@tryghost/adapter-base-scheduling@0.2.2':
dir: packages/adapters/scheduling-base
intents:
- open-shirts-arrive
- young-spiders-request
"@tryghost/adapter-base-scheduling@0.2.3":
'@tryghost/adapter-base-scheduling@0.2.3':
dir: packages/adapters/scheduling-base
intents:
- brown-rules-cut
"@tryghost/adapter-base-sso@0.1.1":
'@tryghost/adapter-base-sso@0.1.1':
dir: packages/adapters/sso-base
intents:
- major-areas-fail
- plain-singers-cheat
"@tryghost/adapter-base-sso@0.1.2":
'@tryghost/adapter-base-sso@0.1.2':
dir: packages/adapters/sso-base
intents:
- open-shirts-arrive
"@tryghost/adapter-base-sso@0.1.3":
'@tryghost/adapter-base-sso@0.1.3':
dir: packages/adapters/sso-base
intents:
- brown-rules-cut
"@tryghost/kg-card-factory@5.2.4":
'@tryghost/kg-card-factory@5.2.4':
dir: koenig/kg-card-factory
intents:
- common-squids-argue
"@tryghost/kg-clean-basic-html@4.3.4":
'@tryghost/kg-clean-basic-html@4.3.4':
dir: koenig/kg-clean-basic-html
intents:
- common-squids-argue
- six-parents-shout
"@tryghost/kg-converters@1.2.4":
'@tryghost/kg-converters@1.2.4':
dir: koenig/kg-converters
intents:
- tidy-types-check
"@tryghost/kg-converters@1.2.5":
'@tryghost/kg-converters@1.2.5':
dir: koenig/kg-converters
intents:
- common-squids-argue
"@tryghost/kg-default-cards@10.3.4":
'@tryghost/kg-default-cards@10.3.4':
dir: koenig/kg-default-cards
intents:
- spacy-poodles-hunt
"@tryghost/kg-default-cards@10.3.5":
'@tryghost/kg-default-cards@10.3.5':
dir: koenig/kg-default-cards
intents:
- common-squids-argue
- six-parents-shout
"@tryghost/kg-default-nodes@2.1.4":
'@tryghost/kg-default-nodes@2.1.4':
dir: koenig/kg-default-nodes
intents:
- floppy-bobcats-spend
"@tryghost/kg-default-nodes@2.1.5":
'@tryghost/kg-default-nodes@2.1.5':
dir: koenig/kg-default-nodes
intents:
- spacy-poodles-hunt
- warm-hotels-make
"@tryghost/kg-default-nodes@2.2.0":
'@tryghost/kg-default-nodes@2.2.0':
dir: koenig/kg-default-nodes
intents:
- clean-flags-retire
- common-squids-argue
- six-parents-shout
"@tryghost/kg-default-transforms@1.3.4":
'@tryghost/kg-default-transforms@1.3.4':
dir: koenig/kg-default-transforms
intents:
- common-squids-argue
"@tryghost/kg-html-to-lexical@1.4.0":
'@tryghost/kg-html-to-lexical@1.4.0':
dir: koenig/kg-html-to-lexical
intents:
- common-squids-argue
- six-parents-shout
"@tryghost/kg-lexical-html-renderer@1.5.0":
'@tryghost/kg-lexical-html-renderer@1.5.0':
dir: koenig/kg-lexical-html-renderer
intents:
- common-squids-argue
- six-parents-shout
"@tryghost/kg-markdown-html-renderer@7.2.4":
'@tryghost/kg-markdown-html-renderer@7.2.4':
dir: koenig/kg-markdown-html-renderer
intents:
- common-squids-argue
- four-rings-relate
"@tryghost/kg-unsplash-selector@0.4.4":
'@tryghost/kg-unsplash-selector@0.4.4':
dir: koenig/kg-unsplash-selector
intents:
- common-squids-argue
- petite-schools-accept
- six-parents-shout
- swift-guests-grin
"@tryghost/kg-utils@1.1.4":
'@tryghost/kg-utils@1.1.4':
dir: koenig/kg-utils
intents:
- common-squids-argue
- four-rings-relate
"@tryghost/koenig-lexical@1.9.0":
'@tryghost/koenig-lexical@1.9.0':
dir: koenig/koenig-lexical
intents:
- bright-walls-preview
"@tryghost/koenig-lexical@1.9.1":
'@tryghost/koenig-lexical@1.9.1':
dir: koenig/koenig-lexical
intents:
- warm-hotels-make
"@tryghost/koenig-lexical@1.9.2":
'@tryghost/koenig-lexical@1.9.2':
dir: koenig/koenig-lexical
intents:
- funky-bikes-chew
Expand All @@ -128,7 +128,7 @@
- petite-forks-lick
- petite-schools-accept
- six-parents-shout
"@tryghost/koenig-lexical@1.9.3":
'@tryghost/koenig-lexical@1.9.3':
dir: koenig/koenig-lexical
intents:
- plenty-moons-smile
Expand Down
1 change: 0 additions & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@
'@tryghost/mw-vhost',
'@tryghost/pretty-cli',
'@tryghost/prometheus-metrics',
'@tryghost/promise',
'@tryghost/referrer-parser',
'@tryghost/root-utils',
'@tryghost/security',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '../../../src/api/member-custom-fields';

// Compile-time cases: the build failing is the assertion. Each `@ts-expect-error` fails the
// build if the case it names stops being an error. Declared on one line each, because the
// directive only covers the line below it and a spread literal reports on its inner line.
// build if the case it names stops being an error. Directives sit immediately above the
// property where TypeScript reports the error.
const composite = { line1: 'a', line2: 'b', city: 'c', state: 'd', postal_code: 'e', country: 'f' };

const labelled: FieldTypePresentation<'address'> = {
Expand All @@ -17,27 +17,27 @@ const labelled: FieldTypePresentation<'address'> = {
subFields: composite,
};

// @ts-expect-error a composite missing one of the parts its value schema declares
const missingPart: FieldTypePresentation<'address'> = {
label: 'Address',
input: 'address',
// @ts-expect-error a composite missing one of the parts its value schema declares
subFields: { line1: 'a', line2: 'b', city: 'c', state: 'd', country: 'f' },
};

// @ts-expect-error a composite naming a part its value schema does not declare
const unknownPart: FieldTypePresentation<'address'> = {
label: 'Address',
input: 'address',
// @ts-expect-error a composite naming a part its value schema does not declare
subFields: { ...composite, county: 'g' },
};

// @ts-expect-error a composite with no part labels at all
const unlabelled: FieldTypePresentation<'address'> = { label: 'Address', input: 'address' };

// @ts-expect-error a type whose value is one thing has no parts to name
const scalarWithParts: FieldTypePresentation<'short_text'> = {
label: 'Short text',
input: 'text',
// @ts-expect-error a type whose value is one thing has no parts to name
subFields: { line1: 'a' },
};

Expand Down
16 changes: 16 additions & 0 deletions apps/admin-x-framework/test/unit/api/posts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,20 @@ describe('posts api', () => {
vi.useRealTimers();
}
});

it('uploads a mapped CSV ZIP through the posts endpoint', async () => {
const file = new File(['PK'], 'posts.zip', { type: 'application/zip' });

await withMockFetch({}, async (mock) => {
const { result } = renderHookWithProviders(() => useImportContentCSV());

await act(async () => {
await result.current.mutateAsync({ file, mapping: { Headline: 'title' } });
});

expect(mock.calls[0][0]).toBe('http://localhost:3000/ghost/api/admin/posts/upload/');
expect(mock.calls[0][1].body.get('postsfile')).toBe(file);
expect(mock.calls[0][1].body.get('mapping[Headline]')).toBe('title');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,97 @@ describe('csv helpers', () => {
]);
});

it('serializes error rows to a downloadable CSV string', () => {
it('serializes error rows into the members export format', () => {
const output = unparseErrorCSV([
{
name: 'Alice',
email: 'bad@example.com',
subscribed: true,
complimentary_plan: false,
labels: [{ name: 'vip' }, { name: 'gold' }],
error: 'Invalid email, "quote"',
},
]);

expect(output).toContain('"name","email","error"');
expect(output).toContain('"Alice","bad@example.com","Invalid email, ""quote"""');
expect(output).toContain(
'"email","name","note","subscribed_to_emails","complimentary_plan","stripe_customer_id","created_at","labels","gift_id","error"',
);
expect(output).toContain('"vip,gold"');
expect(output.split('\n')[1]).toContain('"true"');
expect(output).not.toContain('[object Object]');
expect(output).toContain('"Invalid email, ""quote"""');
});

it('does not invent subscription columns when the source omitted them', () => {
const output = unparseErrorCSV([
{
email: 'a@example.com',
labels: [],
error: 'nope',
},
]);

const [header] = output.split('\r\n');
expect(header).not.toContain('subscribed_to_emails');
expect(header).not.toContain('complimentary_plan');
});

it('drops malformed label entries instead of crashing the download', () => {
const output = unparseErrorCSV([
{
email: 'a@example.com',
labels: [null, { name: 'vip' }, 42, { name: 'gold' }],
error: 'nope',
},
]);

expect(output).toContain('"vip,gold"');
expect(output).not.toContain('[object Object]');
});

it('escapes formula-like values before writing the downloadable CSV', () => {
const output = unparseErrorCSV([
{
name: '=1+2',
email: 'a@example.com',
error: 'nope',
},
]);

expect(output).toContain(`"'=1+2"`);
});

it('keeps a column carried only by a later row, with the error column last', () => {
const output = unparseErrorCSV([
{ email: 'a@example.com', labels: [], error: 'nope' },
{
email: 'b@example.com',
labels: [],
newsletters: [{ name: 'Daily News' }],
'custom_fields.topic': 'ghosts',
error: 'nope',
},
]);

const header = output.split('\n')[0].trimEnd();
expect(header).toContain('"newsletters"');
expect(header).toContain('"custom_fields.topic"');
expect(header.endsWith('"error"')).toBe(true);
});

it('carries the newsletters column only when the submitted file did', () => {
const withColumn = unparseErrorCSV([
{
email: 'a@example.com',
labels: [],
newsletters: [{ name: 'Daily News' }],
error: 'nope',
},
]);
expect(withColumn).toContain('"newsletters"');
expect(withColumn).toContain('"Daily News"');

const withoutColumn = unparseErrorCSV([{ email: 'a@example.com', labels: [], error: 'nope' }]);
expect(withoutColumn.split('\n')[0]).not.toContain('newsletters');
});
});
Loading
Loading