Skip to content
Draft
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
5 changes: 0 additions & 5 deletions packages/app/src/cli/commands/app/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {appFlags} from '../../flags.js'
import {deploy} from '../../services/deploy.js'
import {getAppConfigurationState} from '../../models/app/loader.js'
import {validateVersion} from '../../validations/version-name.js'
import {validateMessage} from '../../validations/message.js'
import metadata from '../../metadata.js'
Expand Down Expand Up @@ -81,10 +80,6 @@ export default class Deploy extends AppLinkedCommand {
}))

const requiredNonTTYFlags = ['force']
const configurationState = await getAppConfigurationState(flags.path, flags.config)
if (configurationState.state === 'template-only' && !clientId) {
requiredNonTTYFlags.push('client-id')
}
this.failMissingNonTTYFlags(flags, requiredNonTTYFlags)

const {app, remoteApp, developerPlatformClient, organization} = await linkedAppContext({
Expand Down
5 changes: 0 additions & 5 deletions packages/app/src/cli/commands/app/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {appFlags} from '../../flags.js'
import {release} from '../../services/release.js'
import AppLinkedCommand, {AppLinkedCommandOutput} from '../../utilities/app-linked-command.js'
import {linkedAppContext} from '../../services/app-context.js'
import {getAppConfigurationState} from '../../models/app/loader.js'
import {Flags} from '@oclif/core'
import {globalFlags} from '@shopify/cli-kit/node/cli'
import {addPublicMetadata} from '@shopify/cli-kit/node/metadata'
Expand Down Expand Up @@ -42,10 +41,6 @@ export default class Release extends AppLinkedCommand {
}))

const requiredNonTTYFlags = ['force']
const configurationState = await getAppConfigurationState(flags.path, flags.config)
if (configurationState.state === 'template-only' && !clientId) {
requiredNonTTYFlags.push('client-id')
}
this.failMissingNonTTYFlags(flags, requiredNonTTYFlags)

const {app, remoteApp, developerPlatformClient} = await linkedAppContext({
Expand Down
31 changes: 7 additions & 24 deletions packages/app/src/cli/models/app/app.test-data.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
App,
AppConfiguration,
AppConfigurationSchema,
AppSchema,
AppConfigurationWithoutPath,
AppInterface,
AppLinkedInterface,
CurrentAppConfiguration,
LegacyAppConfiguration,
WebType,
getAppVersionedSchema,
} from './app.js'
Expand Down Expand Up @@ -93,16 +91,13 @@ export const DEFAULT_CONFIG = {
embedded: true,
access_scopes: {
scopes: 'read_products',
use_legacy_install_flow: true,
},
}

export function testApp(app: Partial<AppInterface> = {}, schemaType: 'current' | 'legacy' = 'legacy'): AppInterface {
const getConfig = () => {
if (schemaType === 'legacy') {
return {scopes: '', extension_directories: [], path: ''}
} else {
return DEFAULT_CONFIG as CurrentAppConfiguration
}
return DEFAULT_CONFIG as CurrentAppConfiguration
}

const newApp = new App({
Expand All @@ -125,7 +120,7 @@ export function testApp(app: Partial<AppInterface> = {}, schemaType: 'current' |
dotenv: app.dotenv,
errors: app.errors,
specifications: app.specifications ?? [],
configSchema: (app.configSchema ?? AppConfigurationSchema) as any,
configSchema: (app.configSchema ?? AppSchema) as any,
remoteFlags: app.remoteFlags ?? [],
hiddenConfig: app.hiddenConfig ?? {},
devApplicationURLs: app.devApplicationURLs,
Expand All @@ -149,20 +144,6 @@ interface TestAppWithConfigOptions {
config: object
}

export function testAppWithLegacyConfig({
app = {},
config = {},
}: TestAppWithConfigOptions): AppInterface<LegacyAppConfiguration> {
const configuration: AppConfiguration = {
path: '',
scopes: '',
name: 'name',
extension_directories: [],
...config,
}
return testApp({...app, configuration}) as AppInterface<LegacyAppConfiguration>
}

export function testAppWithConfig(options?: TestAppWithConfigOptions): AppLinkedInterface {
const app = testAppLinked(options?.app)
app.configuration = {
Expand Down Expand Up @@ -206,7 +187,9 @@ export function testOrganizationApp(app: Partial<OrganizationApp> = {}): Organiz
return {...defaultApp, ...app}
}

export const placeholderAppConfiguration: AppConfigurationWithoutPath = {scopes: ''}
export const placeholderAppConfiguration: AppConfigurationWithoutPath = {
client_id: '',
}

export async function testUIExtension(
uiExtension: Omit<Partial<ExtensionInstance>, 'configuration'> & {
Expand Down
64 changes: 2 additions & 62 deletions packages/app/src/cli/models/app/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {
AppSchema,
CurrentAppConfiguration,
LegacyAppConfiguration,
getAppScopes,
getAppScopesArray,
getUIExtensionRendererVersion,
isCurrentAppSchema,
isLegacyAppSchema,
validateExtensionsHandlesInCollection,
validateFunctionExtensionsWithUiHandle,
} from './app.js'
Expand Down Expand Up @@ -61,43 +58,8 @@ const CORRECT_CURRENT_APP_SCHEMA: CurrentAppConfiguration = {
},
}

const CORRECT_LEGACY_APP_SCHEMA: LegacyAppConfiguration = {
path: '',
extension_directories: [],
web_directories: [],
scopes: 'write_products',
}

describe('app schema validation', () => {
describe('legacy schema validator', () => {
test('checks whether legacy app schema is valid -- pass', () => {
expect(isLegacyAppSchema(CORRECT_LEGACY_APP_SCHEMA)).toBe(true)
})
test('checks whether legacy app schema is valid -- fail', () => {
const config = {
...CORRECT_LEGACY_APP_SCHEMA,
some_other_key: 'i am not valid, i will fail',
}
expect(isLegacyAppSchema(config)).toBe(false)
})
})

describe('current schema validator', () => {
test('checks whether current app schema is valid -- pass', () => {
expect(isCurrentAppSchema(CORRECT_CURRENT_APP_SCHEMA)).toBe(true)
})
test('checks whether current app schema is valid -- fail', () => {
const config = {
...CORRECT_CURRENT_APP_SCHEMA,
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete config.client_id

expect(isCurrentAppSchema(config)).toBe(false)
})

test('extension_directories should be transformed to double asterisks', () => {
const config = {
...CORRECT_CURRENT_APP_SCHEMA,
Expand Down Expand Up @@ -210,24 +172,14 @@ describe('getUIExtensionRendererVersion', () => {
})

describe('getAppScopes', () => {
test('returns the scopes key when schema is legacy', () => {
const config = {path: '', scopes: 'read_themes,read_products'}
expect(getAppScopes(config)).toEqual('read_themes,read_products')
})

test('returns the access_scopes.scopes key when schema is current', () => {
test('returns the access_scopes.scopes key', () => {
const config = {...DEFAULT_CONFIG, access_scopes: {scopes: 'read_themes,read_themes'}}
expect(getAppScopes(config)).toEqual('read_themes,read_themes')
})
})

describe('getAppScopesArray', () => {
test('returns the scopes key when schema is legacy', () => {
const config = {path: '', scopes: 'read_themes, read_order ,write_products'}
expect(getAppScopesArray(config)).toEqual(['read_themes', 'read_order', 'write_products'])
})

test('returns the access_scopes.scopes key when schema is current', () => {
test('returns the access_scopes.scopes key', () => {
const config = {...DEFAULT_CONFIG, access_scopes: {scopes: 'read_themes, read_order ,write_products'}}
expect(getAppScopesArray(config)).toEqual(['read_themes', 'read_order', 'write_products'])
})
Expand Down Expand Up @@ -328,18 +280,6 @@ Learn more: https://shopify.dev/docs/apps/build/authentication-authorization/app
await expect(app.preDeployValidation()).resolves.not.toThrow()
})

test('does not throw an error for legacy schema apps', async () => {
// Given
const configuration: LegacyAppConfiguration = {
...CORRECT_LEGACY_APP_SCHEMA,
scopes: 'read_orders',
}
const app = testApp(configuration, 'legacy')

// When/Then
await expect(app.preDeployValidation()).resolves.not.toThrow()
})

test('handles null/undefined subscriptions safely', async () => {
// Given
const configuration: CurrentAppConfiguration = {
Expand Down
Loading
Loading