|
| 1 | +/* eslint-disable no-restricted-imports */ |
| 2 | +import {mergeFixtureToml} from '../setup/app.js' |
| 3 | +import {expect, test} from '@playwright/test' |
| 4 | +import * as toml from '@iarna/toml' |
| 5 | +import * as fs from 'fs' |
| 6 | +import * as path from 'path' |
| 7 | +import {fileURLToPath} from 'url' |
| 8 | + |
| 9 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 10 | +const VALID_APP_FIXTURE = fs.readFileSync(path.join(__dirname, '../data/valid-app/shopify.app.toml'), 'utf8') |
| 11 | + |
| 12 | +test.describe('fixture TOML', () => { |
| 13 | + test('merges fixture values without dropping template-owned fields', () => { |
| 14 | + const generatedToml = ` |
| 15 | +client_id = "generated-client-id" |
| 16 | +name = "Generated app name" |
| 17 | +application_url = "https://template.example.com" |
| 18 | +
|
| 19 | +[access_scopes] |
| 20 | +scopes = "read_products" |
| 21 | +
|
| 22 | +[sidekick] |
| 23 | +extensions_summary = "Template-provided Sidekick summary" |
| 24 | +template_owned = true |
| 25 | +`.trimStart() |
| 26 | + |
| 27 | + const fixtureToml = ` |
| 28 | +client_id = "placeholder" |
| 29 | +name = "placeholder" |
| 30 | +application_url = "https://fixture.example.com" |
| 31 | +
|
| 32 | +[build] |
| 33 | +include_config_on_deploy = true |
| 34 | +
|
| 35 | +[sidekick] |
| 36 | +extensions_summary = "Fixture-provided Sidekick summary" |
| 37 | +`.trimStart() |
| 38 | + |
| 39 | + const mergedToml = mergeFixtureToml(generatedToml, fixtureToml, 'E2E merged app') |
| 40 | + const parsed = toml.parse(mergedToml) |
| 41 | + |
| 42 | + expect(parsed.client_id).toBe('generated-client-id') |
| 43 | + expect(parsed.name).toBe('E2E merged app') |
| 44 | + expect(parsed.application_url).toBe('https://fixture.example.com') |
| 45 | + expect(parsed.access_scopes).toEqual({scopes: 'read_products'}) |
| 46 | + expect(parsed.sidekick).toEqual({ |
| 47 | + extensions_summary: 'Fixture-provided Sidekick summary', |
| 48 | + template_owned: true, |
| 49 | + }) |
| 50 | + expect(parsed.build).toEqual({include_config_on_deploy: true}) |
| 51 | + }) |
| 52 | + |
| 53 | + test('valid app fixture can merge into generated template TOML', () => { |
| 54 | + const generatedToml = ` |
| 55 | +client_id = "generated-client-id" |
| 56 | +name = "Generated app name" |
| 57 | +
|
| 58 | +[sidekick] |
| 59 | +extensions_summary = "Template-provided Sidekick summary" |
| 60 | +template_owned = true |
| 61 | +
|
| 62 | +[template_owned] |
| 63 | +kept = true |
| 64 | +`.trimStart() |
| 65 | + |
| 66 | + const mergedToml = mergeFixtureToml(generatedToml, VALID_APP_FIXTURE, 'E2E valid fixture app') |
| 67 | + const parsed = toml.parse(mergedToml) |
| 68 | + |
| 69 | + expect(parsed.client_id).toBe('generated-client-id') |
| 70 | + expect(parsed.name).toBe('E2E valid fixture app') |
| 71 | + expect(parsed.template_owned).toEqual({kept: true}) |
| 72 | + expect(parsed.sidekick).toEqual({ |
| 73 | + extensions_summary: 'Read, create, and edit FAQ entries stored in the app', |
| 74 | + template_owned: true, |
| 75 | + }) |
| 76 | + expect(parsed.webhooks).toMatchObject({api_version: '2025-01'}) |
| 77 | + expect((parsed.webhooks as {subscriptions: unknown[]}).subscriptions).toHaveLength(2) |
| 78 | + }) |
| 79 | +}) |
0 commit comments