Skip to content

Commit

Permalink
Merge pull request #5182 from google/enhance/4803-module-recovery-fol…
Browse files Browse the repository at this point in the history
…low-up

Enhance/4803 - Module recovery follow up
  • Loading branch information
techanvil authored May 5, 2022
2 parents 7cb35f5 + 080f2f2 commit ce19818
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
13 changes: 12 additions & 1 deletion assets/js/googlesitekit/modules/datastore/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,20 @@ const baseActions = {

// Reload all modules from the server.
yield fetchGetModulesStore.actions.fetchGetModules();

return {
response: {
success: true,
},
};
}

return { response, error };
return {
response: {
success: false,
},
error,
};
}
),
};
Expand Down
34 changes: 18 additions & 16 deletions assets/js/googlesitekit/modules/datastore/modules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe( 'core/modules modules', () => {
.dispatch( CORE_MODULES )
.recoverModule( slug );

expect( response.ownerID ).toBe( 1 );
expect( response.success ).toBe( true );

expect( fetchMock ).toHaveFetchedTimes( 4 );

Expand Down Expand Up @@ -270,14 +270,14 @@ describe( 'core/modules modules', () => {
{ body: FIXTURES, status: 200 }
);

const apiResponse = {
const errorResponse = {
code: 'module_not_recoverable',
message: 'Module is not recoverable.',
data: { status: 403 },
};
fetchMock.postOnce(
/^\/google-site-kit\/v1\/core\/modules\/data\/recover-module/,
{ body: apiResponse }
{ body: errorResponse, status: 403 }
);

const initialModules = registry
Expand All @@ -288,11 +288,13 @@ describe( 'core/modules modules', () => {
expect( initialModules ).toBeUndefined();
await untilResolved( registry, CORE_MODULES ).getModules();

const { response } = await registry
const { response, error } = await registry
.dispatch( CORE_MODULES )
.recoverModule( slug );

expect( response.message ).toBe( apiResponse.message );
expect( console ).toHaveErrored();
expect( response.success ).toBe( false );
expect( error.message ).toBe( errorResponse.message );

expect( fetchMock ).toHaveFetchedTimes( 2 );

Expand Down Expand Up @@ -321,21 +323,21 @@ describe( 'core/modules modules', () => {
);
} );

it( 'encourters an error if an invalid module slug is passed', async () => {
it( 'encounters an error if an invalid module slug is passed', async () => {
const slug = 'invalid-slug';
fetchMock.get(
/^\/google-site-kit\/v1\/core\/modules\/data\/list/,
{ body: FIXTURES, status: 200 }
);

const apiResponse = {
const errorResponse = {
code: 'invalid_module_slug',
message: `Invalid module slug ${ slug }.`,
data: { status: 404 },
};
fetchMock.postOnce(
/^\/google-site-kit\/v1\/core\/modules\/data\/recover-module/,
{ body: apiResponse }
{ body: errorResponse, status: 403 }
);

const initialModules = registry
Expand All @@ -346,11 +348,13 @@ describe( 'core/modules modules', () => {
expect( initialModules ).toBeUndefined();
await untilResolved( registry, CORE_MODULES ).getModules();

const { response } = await registry
const { response, error } = await registry
.dispatch( CORE_MODULES )
.recoverModule( slug );

expect( response.message ).toBe( apiResponse.message );
expect( console ).toHaveErrored();
expect( response.success ).toBe( false );
expect( error.message ).toBe( errorResponse.message );

expect( fetchMock ).toHaveFetchedTimes( 2 );

Expand Down Expand Up @@ -1367,13 +1371,11 @@ describe( 'core/modules modules', () => {
{ body: FIXTURES, status: 200 }
);

const recoverableModules = registry
.select( CORE_MODULES )
.getRecoverableModules();
registry.select( CORE_MODULES ).getRecoverableModules();

registry.select( CORE_MODULES ).getModules();
const modules = registry.select( CORE_MODULES ).getModules();

expect( recoverableModules ).toBeUndefined();
expect( modules ).toBeUndefined();
} );

it( 'should return an empty object if there is no `recoverableModules`', async () => {
Expand Down Expand Up @@ -1403,7 +1405,7 @@ describe( 'core/modules modules', () => {
expect( recoverableModules ).toMatchObject( {} );
} );

it( 'should return the modules object for each recoverable modules', async () => {
it( 'should return the modules object for each recoverable module', async () => {
global[ dashboardSharingDataBaseVar ] = recoverableModuleList;

fetchMock.getOnce(
Expand Down

0 comments on commit ce19818

Please sign in to comment.