Skip to content

Commit 3030250

Browse files
committed
Force all requests in app management to have an unauthorizedHandler
1 parent 7b973d3 commit 3030250

File tree

9 files changed

+389
-327
lines changed

9 files changed

+389
-327
lines changed

packages/app/src/cli/utilities/developer-platform-client/app-management-client.test.ts

Lines changed: 99 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,23 @@ describe('templateSpecifications', () => {
184184
const gotLabels = got.map((template) => template.name)
185185

186186
// Then
187-
expect(vi.mocked(businessPlatformOrganizationsRequest)).toHaveBeenCalledWith(
188-
`
187+
expect(vi.mocked(businessPlatformOrganizationsRequest)).toHaveBeenCalledWith({
188+
query: `
189189
query OrganizationBetaFlags($organizationId: OrganizationID!) {
190190
organization(organizationId: $organizationId) {
191191
id
192192
flag_allowedFlag: hasFeatureFlag(handle: "allowedFlag")
193193
flag_notAllowedFlag: hasFeatureFlag(handle: "notAllowedFlag")
194194
}
195195
}`,
196-
'business-platform-token',
197-
orgApp.organizationId,
198-
{organizationId: encodedGidFromOrganizationId(orgApp.organizationId)},
199-
)
196+
token: 'business-platform-token',
197+
organizationId: orgApp.organizationId,
198+
variables: {organizationId: encodedGidFromOrganizationId(orgApp.organizationId)},
199+
unauthorizedHandler: {
200+
type: 'token_refresh',
201+
handler: expect.any(Function),
202+
},
203+
})
200204
const expectedAllowedTemplates = [templateWithoutRules, allowedTemplate]
201205
expect(gotLabels).toEqual(expectedAllowedTemplates.map((template) => template.name))
202206
})
@@ -308,18 +312,16 @@ describe('searching for apps', () => {
308312
const got = await client.appsForOrg(orgId, query)
309313

310314
// Then
311-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
312-
orgId,
313-
ListApps,
314-
'token',
315-
{query: queryVariable},
316-
undefined,
317-
undefined,
318-
expect.objectContaining({
319-
handler: expect.any(Function),
315+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
316+
organizationId: orgId,
317+
query: ListApps,
318+
token: 'token',
319+
variables: {query: queryVariable},
320+
unauthorizedHandler: {
320321
type: 'token_refresh',
321-
}),
322-
)
322+
handler: expect.any(Function),
323+
},
324+
})
323325
expect(got).toEqual({
324326
apps: apps.map((app, index) => ({
325327
apiKey: `key-${index}`,
@@ -367,11 +369,11 @@ describe('createApp', () => {
367369

368370
// Then
369371
expect(webhooksRequest).toHaveBeenCalledWith(org.id, expect.anything(), 'token', expect.any(Object))
370-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
371-
org.id,
372-
CreateApp,
373-
'token',
374-
{
372+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
373+
organizationId: org.id,
374+
query: CreateApp,
375+
token: 'token',
376+
variables: {
375377
initialVersion: {
376378
source: {
377379
name: 'app-name',
@@ -386,13 +388,11 @@ describe('createApp', () => {
386388
},
387389
},
388390
},
389-
undefined,
390-
undefined,
391-
expect.objectContaining({
391+
unauthorizedHandler: {
392392
handler: expect.any(Function),
393393
type: 'token_refresh',
394-
}),
395-
)
394+
},
395+
})
396396
})
397397

398398
test('creates app successfully and returns expected app structure', async () => {
@@ -458,11 +458,11 @@ describe('createApp', () => {
458458
await client.createApp(org, {name: 'app-name'})
459459

460460
// Then
461-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
462-
org.id,
463-
CreateApp,
464-
'token',
465-
{
461+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
462+
organizationId: org.id,
463+
query: CreateApp,
464+
token: 'token',
465+
variables: {
466466
initialVersion: {
467467
source: {
468468
name: 'app-name',
@@ -478,13 +478,11 @@ describe('createApp', () => {
478478
},
479479
},
480480
},
481-
undefined,
482-
undefined,
483-
expect.objectContaining({
481+
unauthorizedHandler: {
484482
handler: expect.any(Function),
485483
type: 'token_refresh',
486-
}),
487-
)
484+
},
485+
})
488486
})
489487
})
490488

@@ -716,11 +714,11 @@ describe('deploy', () => {
716714
})
717715

718716
// Then
719-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
720-
'gid://shopify/Organization/123',
721-
expect.anything(),
722-
'token',
723-
{
717+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
718+
organizationId: 'gid://shopify/Organization/123',
719+
query: expect.anything(),
720+
token: 'token',
721+
variables: {
724722
appId: 'gid://shopify/App/123',
725723
version: {
726724
source: {
@@ -742,13 +740,12 @@ describe('deploy', () => {
742740
sourceControlUrl: commitReference,
743741
},
744742
},
745-
undefined,
746-
{requestMode: 'slow-request'},
747-
expect.objectContaining({
743+
requestOptions: {requestMode: 'slow-request'},
744+
unauthorizedHandler: {
748745
handler: expect.any(Function),
749746
type: 'token_refresh',
750-
}),
751-
)
747+
},
748+
})
752749
})
753750

754751
test('includes the target property when context is provided', async () => {
@@ -800,11 +797,11 @@ describe('deploy', () => {
800797
})
801798

802799
// Then
803-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
804-
'gid://shopify/Organization/123',
805-
expect.anything(),
806-
'token',
807-
{
800+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
801+
organizationId: 'gid://shopify/Organization/123',
802+
query: expect.anything(),
803+
token: 'token',
804+
variables: {
808805
appId: 'gid://shopify/App/123',
809806
version: {
810807
source: {
@@ -826,13 +823,12 @@ describe('deploy', () => {
826823
sourceControlUrl: commitReference,
827824
},
828825
},
829-
undefined,
830-
{requestMode: 'slow-request'},
831-
expect.objectContaining({
826+
requestOptions: {requestMode: 'slow-request'},
827+
unauthorizedHandler: {
832828
handler: expect.any(Function),
833829
type: 'token_refresh',
834-
}),
835-
)
830+
},
831+
})
836832
})
837833

838834
test('does not include target property when context is empty', async () => {
@@ -884,11 +880,11 @@ describe('deploy', () => {
884880
})
885881

886882
// Then
887-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
888-
'gid://shopify/Organization/123',
889-
expect.anything(),
890-
'token',
891-
{
883+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
884+
organizationId: 'gid://shopify/Organization/123',
885+
query: expect.anything(),
886+
token: 'token',
887+
variables: {
892888
appId: 'gid://shopify/App/123',
893889
version: {
894890
source: {
@@ -910,13 +906,12 @@ describe('deploy', () => {
910906
sourceControlUrl: commitReference,
911907
},
912908
},
913-
undefined,
914-
expect.objectContaining({requestMode: 'slow-request'}),
915-
expect.objectContaining({
909+
requestOptions: {requestMode: 'slow-request'},
910+
unauthorizedHandler: {
916911
handler: expect.any(Function),
917912
type: 'token_refresh',
918-
}),
919-
)
913+
},
914+
})
920915
})
921916

922917
test('uses bundleUrl when provided instead of modules', async () => {
@@ -946,24 +941,23 @@ describe('deploy', () => {
946941
})
947942

948943
// Then
949-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
950-
'gid://shopify/Organization/123',
951-
expect.anything(),
952-
'token',
953-
{
944+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
945+
organizationId: 'gid://shopify/Organization/123',
946+
query: expect.anything(),
947+
token: 'token',
948+
variables: {
954949
appId: 'gid://shopify/App/123',
955950
version: {
956951
sourceUrl: bundleUrl,
957952
},
958953
metadata: expect.any(Object),
959954
},
960-
undefined,
961-
expect.objectContaining({requestMode: 'slow-request'}),
962-
expect.objectContaining({
955+
requestOptions: {requestMode: 'slow-request'},
956+
unauthorizedHandler: {
963957
handler: expect.any(Function),
964958
type: 'token_refresh',
965-
}),
966-
)
959+
},
960+
})
967961
})
968962

969963
test('updates name from branding module if present', async () => {
@@ -1001,25 +995,24 @@ describe('deploy', () => {
1001995
})
1002996

1003997
// Then
1004-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
1005-
'gid://shopify/Organization/123',
1006-
expect.anything(),
1007-
'token',
1008-
expect.objectContaining({
998+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
999+
organizationId: 'gid://shopify/Organization/123',
1000+
query: expect.anything(),
1001+
token: 'token',
1002+
variables: expect.objectContaining({
10091003
version: {
10101004
source: {
10111005
name: 'Updated App Name',
10121006
modules: expect.any(Array),
10131007
},
10141008
},
10151009
}),
1016-
undefined,
1017-
expect.objectContaining({requestMode: 'slow-request'}),
1018-
expect.objectContaining({
1010+
requestOptions: {requestMode: 'slow-request'},
1011+
unauthorizedHandler: {
10191012
handler: expect.any(Function),
10201013
type: 'token_refresh',
1021-
}),
1022-
)
1014+
},
1015+
})
10231016
})
10241017

10251018
test('handles version creation errors', async () => {
@@ -1147,18 +1140,16 @@ describe('deploy', () => {
11471140
})
11481141

11491142
// Then
1150-
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith(
1151-
'gid://shopify/Organization/123',
1152-
AppVersions,
1153-
'token',
1154-
expect.objectContaining({appId}),
1155-
undefined,
1156-
undefined,
1157-
expect.objectContaining({
1143+
expect(vi.mocked(appManagementRequestDoc)).toHaveBeenCalledWith({
1144+
organizationId: 'gid://shopify/Organization/123',
1145+
query: AppVersions,
1146+
token: 'token',
1147+
variables: expect.objectContaining({appId}),
1148+
unauthorizedHandler: {
11581149
handler: expect.any(Function),
11591150
type: 'token_refresh',
1160-
}),
1161-
)
1151+
},
1152+
})
11621153
expect(result).toEqual({
11631154
app: {
11641155
id: appId,
@@ -1224,22 +1215,21 @@ describe('AppManagementClient', () => {
12241215
await client.generateSignedUploadUrl(app)
12251216

12261217
// Then
1227-
expect(appManagementRequestDoc).toHaveBeenCalledWith(
1228-
app.organizationId,
1229-
CreateAssetUrl,
1230-
'token',
1231-
{
1218+
expect(appManagementRequestDoc).toHaveBeenCalledWith({
1219+
organizationId: app.organizationId,
1220+
query: CreateAssetUrl,
1221+
token: 'token',
1222+
variables: expect.objectContaining({
12321223
sourceExtension: 'BR' as SourceExtension,
1233-
},
1234-
expect.objectContaining({
1235-
cacheTTL: expect.anything(),
12361224
}),
1237-
undefined,
1238-
expect.objectContaining({
1225+
unauthorizedHandler: {
12391226
handler: expect.any(Function),
12401227
type: 'token_refresh',
1241-
}),
1242-
)
1228+
},
1229+
cacheOptions: {
1230+
cacheTTL: {minutes: 59},
1231+
},
1232+
})
12431233
})
12441234
})
12451235

0 commit comments

Comments
 (0)