Skip to content

Commit

Permalink
Cleanup 'canUser' unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 10, 2024
1 parent b75f6ab commit 25148e4
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions packages/core-data/src/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,21 @@ describe( 'getEmbedPreview', () => {
} );

describe( 'canUser', () => {
let registry;
let dispatch, registry;
beforeEach( async () => {
registry = {
select: jest.fn( () => ( {
hasStartedResolution: () => false,
} ) ),
batch: ( callback ) => callback(),
};
dispatch = Object.assign( jest.fn(), {
receiveUserPermission: jest.fn(),
} );
triggerFetch.mockReset();
} );

it( 'does nothing when there is an API error', async () => {
const dispatch = Object.assign( jest.fn(), {
receiveUserPermission: jest.fn(),
} );

triggerFetch.mockImplementation( () =>
Promise.reject( { status: 404 } )
);
Expand All @@ -315,10 +314,6 @@ describe( 'canUser', () => {
} );

it( 'receives false when the user is not allowed to perform an action', async () => {
const dispatch = Object.assign( jest.fn(), {
receiveUserPermission: jest.fn(),
} );

triggerFetch.mockImplementation( () => ( {
headers: new Map( [ [ 'allow', 'GET' ] ] ),
} ) );
Expand All @@ -338,10 +333,6 @@ describe( 'canUser', () => {
} );

it( 'receives true when the user is allowed to perform an action', async () => {
const dispatch = Object.assign( jest.fn(), {
receiveUserPermission: jest.fn(),
} );

triggerFetch.mockImplementation( () => ( {
headers: new Map( [ [ 'allow', 'POST, GET, PUT, DELETE' ] ] ),
} ) );
Expand All @@ -361,10 +352,6 @@ describe( 'canUser', () => {
} );

it( 'receives true when the user is allowed to perform an action on a specific resource', async () => {
const dispatch = Object.assign( jest.fn(), {
receiveUserPermission: jest.fn(),
} );

triggerFetch.mockImplementation( () => ( {
headers: new Map( [ [ 'allow', 'POST, GET, PUT, DELETE' ] ] ),
} ) );
Expand All @@ -384,10 +371,6 @@ describe( 'canUser', () => {
} );

it( 'runs apiFetch only once per resource', async () => {
const dispatch = Object.assign( jest.fn(), {
receiveUserPermission: jest.fn(),
} );

registry = {
...registry,
select: () => ( {
Expand Down Expand Up @@ -415,10 +398,6 @@ describe( 'canUser', () => {
} );

it( 'retrieves all permissions even when ID is not given', async () => {
const dispatch = Object.assign( jest.fn(), {
receiveUserPermission: jest.fn(),
} );

registry = {
...registry,
select: () => ( {
Expand Down Expand Up @@ -454,10 +433,6 @@ describe( 'canUser', () => {
} );

it( 'runs apiFetch only once per resource ID', async () => {
const dispatch = Object.assign( jest.fn(), {
receiveUserPermission: jest.fn(),
} );

registry = {
...registry,
select: () => ( {
Expand Down

0 comments on commit 25148e4

Please sign in to comment.