@@ -7,94 +7,121 @@ import {
7
7
setUpEmbeddedFlow ,
8
8
setUpFetchFlow ,
9
9
setUpNonEmbeddedFlow ,
10
+ setUpEmbeddedFlowWithSingleFetch ,
10
11
} from '../../../../__test-helpers' ;
11
12
import { REAUTH_URL_HEADER } from '../../../const' ;
12
13
13
14
import * as responses from './mock-responses' ;
14
15
15
- it ( 'returns scopes information' , async ( ) => {
16
- // GIVEN
17
- const { scopes} = await setUpEmbeddedFlow ( ) ;
18
- await mockGraphqlRequest ( ) ( {
19
- status : 200 ,
20
- responseContent : responses . WITH_GRANTED_AND_DECLARED ,
16
+ describe . each ( [
17
+ [ 'with standard embedded flow' , setUpEmbeddedFlow ] ,
18
+ [ 'with single fetch embedded flow' , setUpEmbeddedFlowWithSingleFetch ] ,
19
+ ] ) ( '%s' , ( _ , setupFn ) => {
20
+ it ( 'returns scopes information' , async ( ) => {
21
+ // GIVEN
22
+ const { scopes} = await setupFn ( ) ;
23
+ await mockGraphqlRequest ( ) ( {
24
+ status : 200 ,
25
+ responseContent : responses . WITH_GRANTED_AND_DECLARED ,
26
+ } ) ;
27
+
28
+ // WHEN
29
+ const result = await scopes . query ( ) ;
30
+ // THEN
31
+ expect ( result ) . not . toBeUndefined ( ) ;
32
+ expect ( result . granted ) . toEqual ( [
33
+ 'read_orders' ,
34
+ 'read_reports' ,
35
+ 'read_products' ,
36
+ 'read_customers' ,
37
+ 'write_customers' ,
38
+ ] ) ;
39
+ expect ( result . required ) . toEqual ( [
40
+ 'read_orders' ,
41
+ 'read_reports' ,
42
+ 'read_products' ,
43
+ ] ) ;
44
+ expect ( result . optional ) . toEqual ( [ 'write_customers' , 'write_products' ] ) ;
21
45
} ) ;
22
46
23
- // WHEN
24
- const result = await scopes . query ( ) ;
25
- // THEN
26
- expect ( result ) . not . toBeUndefined ( ) ;
27
- expect ( result . granted ) . toEqual ( [
28
- 'read_orders' ,
29
- 'read_reports' ,
30
- 'read_products' ,
31
- 'read_customers' ,
32
- 'write_customers' ,
33
- ] ) ;
34
- expect ( result . required ) . toEqual ( [
35
- 'read_orders' ,
36
- 'read_reports' ,
37
- 'read_products' ,
38
- ] ) ;
39
- expect ( result . optional ) . toEqual ( [ 'write_customers' , 'write_products' ] ) ;
40
- } ) ;
47
+ it ( 'redirects to exit-iframe with authentication using app bridge when embedded and Shopify invalidated the session' , async ( ) => {
48
+ // GIVEN
49
+ const { scopes} = await setupFn ( ) ;
50
+ const requestMock = await mockGraphqlRequest ( ) ( { status : 401 } ) ;
41
51
42
- it ( 'redirects to exit-iframe with authentication using app bridge when embedded and Shopify invalidated the session' , async ( ) => {
43
- // GIVEN
44
- const { scopes} = await setUpEmbeddedFlow ( ) ;
45
- const requestMock = await mockGraphqlRequest ( ) ( { status : 401 } ) ;
52
+ // WHEN
53
+ const response = await getThrownResponse (
54
+ async ( ) => scopes . query ( ) ,
55
+ requestMock ,
56
+ ) ;
46
57
47
- // WHEN
48
- const response = await getThrownResponse (
49
- async ( ) => scopes . query ( ) ,
50
- requestMock ,
51
- ) ;
52
-
53
- // THEN
54
- expectExitIframeRedirect ( response ) ;
58
+ // THEN
59
+ expectExitIframeRedirect ( response ) ;
60
+ } ) ;
55
61
} ) ;
56
62
57
- it ( 'returns app bridge redirection during request headers when Shopify invalidated the session' , async ( ) => {
58
- // GIVEN
59
- const { scopes} = await setUpFetchFlow ( {
60
- unstable_newEmbeddedAuthStrategy : false ,
63
+ describe . each ( [
64
+ [ 'with standard fetch flow' , false ] ,
65
+ [ 'with single fetch flow' , true ] ,
66
+ ] ) ( '%s' , ( _ , remixSingleFetch ) => {
67
+ it ( 'returns app bridge redirection during request headers when Shopify invalidated the session' , async ( ) => {
68
+ // GIVEN
69
+ const { scopes} = await setUpFetchFlow ( {
70
+ unstable_newEmbeddedAuthStrategy : false ,
71
+ remixSingleFetch,
72
+ } ) ;
73
+ const requestMock = await mockGraphqlRequest ( ) ( { status : 401 } ) ;
74
+
75
+ // WHEN
76
+ const response = await getThrownResponse (
77
+ async ( ) => scopes . query ( ) ,
78
+ requestMock ,
79
+ ) ;
80
+
81
+ // THEN
82
+ expect ( response . status ) . toEqual ( remixSingleFetch ? 302 : 401 ) ;
83
+
84
+ const { origin, pathname, searchParams} = new URL (
85
+ response . headers . get ( REAUTH_URL_HEADER ) ! ,
86
+ ) ;
87
+ expect ( origin ) . toEqual ( APP_URL ) ;
88
+ expect ( pathname ) . toEqual ( '/auth' ) ;
89
+ expect ( searchParams . get ( 'shop' ) ) . toEqual ( TEST_SHOP ) ;
61
90
} ) ;
62
- const requestMock = await mockGraphqlRequest ( ) ( { status : 401 } ) ;
63
91
64
- // WHEN
65
- const response = await getThrownResponse (
66
- async ( ) => scopes . query ( ) ,
67
- requestMock ,
68
- ) ;
92
+ it ( 'returns a normal redirection when the app is non embedded and Shopify invalidated the session' , async ( ) => {
93
+ // GIVEN
94
+ const { scopes} = await setUpNonEmbeddedFlow ( ) ;
95
+ const requestMock = await mockGraphqlRequest ( ) ( { status : 401 } ) ;
69
96
70
- // THEN
71
- expect ( response . status ) . toEqual ( 302 ) ;
97
+ // WHEN
98
+ const response = await getThrownResponse (
99
+ async ( ) => scopes . query ( ) ,
100
+ requestMock ,
101
+ ) ;
72
102
73
- const { origin, pathname, searchParams} = new URL (
74
- response . headers . get ( REAUTH_URL_HEADER ) ! ,
75
- ) ;
76
- expect ( origin ) . toEqual ( APP_URL ) ;
77
- expect ( pathname ) . toEqual ( '/auth' ) ;
78
- expect ( searchParams . get ( 'shop' ) ) . toEqual ( TEST_SHOP ) ;
103
+ // THEN
104
+ expect ( response . status ) . toEqual ( 302 ) ;
105
+
106
+ const { hostname, pathname} = new URL ( response . headers . get ( 'Location' ) ! ) ;
107
+ expect ( hostname ) . toEqual ( TEST_SHOP ) ;
108
+ expect ( pathname ) . toEqual ( '/admin/oauth/authorize' ) ;
109
+ } ) ;
79
110
} ) ;
80
111
81
- it ( 'returns a normal redirection when the app is non embedded and Shopify invalidated the session ' , async ( ) => {
112
+ it ( 'return an unexpected error when there is no authentication error ' , async ( ) => {
82
113
// GIVEN
83
- const { scopes} = await setUpNonEmbeddedFlow ( ) ;
84
- const requestMock = await mockGraphqlRequest ( ) ( { status : 401 } ) ;
114
+ const { scopes} = await setUpFetchFlow ( {
115
+ unstable_newEmbeddedAuthStrategy : false ,
116
+ } ) ;
117
+ await mockGraphqlRequest ( ) ( { status : 500 } ) ;
85
118
86
- // WHEN
87
- const response = await getThrownResponse (
88
- async ( ) => scopes . query ( ) ,
89
- requestMock ,
119
+ // WHEN / THEN
120
+ await expect ( scopes . query ( ) ) . rejects . toEqual (
121
+ expect . objectContaining ( {
122
+ status : 500 ,
123
+ } ) ,
90
124
) ;
91
-
92
- // THEN
93
- expect ( response . status ) . toEqual ( 302 ) ;
94
-
95
- const { hostname, pathname} = new URL ( response . headers . get ( 'Location' ) ! ) ;
96
- expect ( hostname ) . toEqual ( TEST_SHOP ) ;
97
- expect ( pathname ) . toEqual ( '/admin/oauth/authorize' ) ;
98
125
} ) ;
99
126
100
127
it ( 'return an unexpected error when there is no authentication error' , async ( ) => {
0 commit comments