Skip to content

Commit a164c24

Browse files
sixhoursJessBoctor
authored andcommitted
Site Migration: Transfer with software API, update hooks (Automattic#102248)
* Update query hook types and tests * Remove unused response params * use correct response type * Make siteId and transferId nullable; update success => completed * Account for potentially null values
1 parent c3e77e9 commit a164c24

4 files changed

+15
-43
lines changed

client/sites/hooks/test/use-transfer-with-software-start-mutation.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ describe( 'useRequestTransferWithSoftware', () => {
6767
atomic_transfer_id: 456,
6868
blog_id: SITE_ID,
6969
atomic_transfer_status: 'pending',
70-
plugins: { 'plugin-1': 'install' },
71-
themes: { 'theme-1': 'activate' },
72-
transfer_with_software_status: 'pending',
7370
} );
7471

7572
const { result } = render();
@@ -83,9 +80,6 @@ describe( 'useRequestTransferWithSoftware', () => {
8380
atomic_transfer_id: 456,
8481
blog_id: SITE_ID,
8582
atomic_transfer_status: 'pending',
86-
plugins: { 'plugin-1': 'install' },
87-
themes: { 'theme-1': 'activate' },
88-
transfer_with_software_status: 'pending',
8983
} );
9084
},
9185
{ timeout: 3000 }

client/sites/hooks/test/use-transfer-with-software-status-query.tsx

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ jest.mock( '@automattic/calypso-config', () => ( {
1616
const mockSuccessResponse = {
1717
blog_id: 123,
1818
atomic_transfer_id: 456,
19-
transfer_with_software_status: 'pending',
20-
atomic_transfer_status: 'success',
21-
plugins: { 'wpcom-migration': true },
22-
themes: { 'twenty-twenty-four': false },
19+
atomic_transfer_status: 'completed',
2320
};
2421

2522
describe( 'useTransferWithSoftwareStatus', () => {
@@ -44,8 +41,7 @@ describe( 'useTransferWithSoftwareStatus', () => {
4441
await waitFor( () => {
4542
expect( result.current.isSuccess ).toBe( true );
4643
expect( result.current.data ).toEqual( {
47-
transfer_with_software_status: 'pending',
48-
atomic_transfer_status: 'success',
44+
atomic_transfer_status: 'completed',
4945
} );
5046
} );
5147
} );
@@ -71,22 +67,4 @@ describe( 'useTransferWithSoftwareStatus', () => {
7167
expect( result.current.isFetching ).toBe( false );
7268
expect( nock.isDone() ).toBe( true ); // No pending nock requests
7369
} );
74-
75-
it( 'should ignore extra fields in the response', async () => {
76-
const queryClient = new QueryClient();
77-
const wrapper = ( { children }: { children: React.ReactNode } ) => (
78-
<QueryClientProvider client={ queryClient }>{ children }</QueryClientProvider>
79-
);
80-
nock( 'https://public-api.wordpress.com' )
81-
.get( '/wpcom/v2/sites/123/atomic/transfer-with-software/456' )
82-
.query( { http_envelope: 1 } )
83-
.reply( 200, mockSuccessResponse );
84-
85-
const { result } = renderHook( () => useTransferWithSoftwareStatus( 123, 456 ), { wrapper } );
86-
87-
await waitFor( () => {
88-
expect( result.current.isSuccess ).toBe( true );
89-
expect( result.current.data ).not.toContain( { extra_field: 'extra_value' } );
90-
} );
91-
} );
9270
} );

client/sites/hooks/use-transfer-with-software-start-mutation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ type TransferWithSoftwareResponse = {
55
blog_id: number;
66
atomic_transfer_id: number;
77
atomic_transfer_status: string;
8-
plugins: Record< string, string >;
9-
themes: Record< string, string >;
10-
transfer_with_software_status: string;
118
};
129

1310
type SoftwareSlug = string;

client/sites/hooks/use-transfer-with-software-status-query.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import wpcom from 'calypso/lib/wp';
44
type TransferWithSoftwareStatusResponse = {
55
blog_id: number;
66
atomic_transfer_id: number;
7-
plugins: { [ key: string ]: boolean };
8-
themes: { [ key: string ]: boolean };
9-
transfer_with_software_status: string;
107
atomic_transfer_status: string;
118
};
129

13-
const getTransferWithSoftwareStatus = async (
14-
siteId: number,
15-
atomicTransferId: number
16-
): Promise< TransferWithSoftwareStatusResponse > => {
10+
const getTransferWithSoftwareStatus: (
11+
siteId?: number,
12+
atomicTransferId?: number
13+
) => Promise< TransferWithSoftwareStatusResponse > = async ( siteId, atomicTransferId ) => {
14+
if ( ! siteId || ! atomicTransferId ) {
15+
return {
16+
blog_id: 0,
17+
atomic_transfer_id: 0,
18+
atomic_transfer_status: 'pending',
19+
};
20+
}
1721
return wpcom.req.get(
1822
`/sites/${ siteId }/atomic/transfer-with-software/${ atomicTransferId }?http_envelope=1`,
1923
{
@@ -23,8 +27,8 @@ const getTransferWithSoftwareStatus = async (
2327
};
2428

2529
export const useTransferWithSoftwareStatus = (
26-
siteId: number,
27-
atomicTransferId: number,
30+
siteId?: number,
31+
atomicTransferId?: number,
2832
options?: {
2933
retry?: UseQueryOptions[ 'retry' ];
3034
}
@@ -33,7 +37,6 @@ export const useTransferWithSoftwareStatus = (
3337
queryKey: [ 'software-transfer-status', siteId, atomicTransferId ],
3438
queryFn: () => getTransferWithSoftwareStatus( siteId, atomicTransferId ),
3539
select: ( data: TransferWithSoftwareStatusResponse ) => ( {
36-
transfer_with_software_status: data.transfer_with_software_status,
3740
atomic_transfer_status: data.atomic_transfer_status,
3841
} ),
3942
refetchOnWindowFocus: false,

0 commit comments

Comments
 (0)