-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improve access service iter 2 (#4779)
## About the changes In #4689 I forgot to add backward compatibility for a public method that was being used in Enterprise.
- Loading branch information
1 parent
013efac
commit bed0a29
Showing
11 changed files
with
279 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import dbInit from '../../test/e2e/helpers/database-init'; | ||
import getLogger from '../../test/fixtures/no-logger'; | ||
import { PermissionRef } from 'lib/services/access-service'; | ||
import { AccessStore } from './access-store'; | ||
|
||
let db; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('access_store_serial', getLogger); | ||
}); | ||
|
||
afterAll(async () => { | ||
if (db) { | ||
await db.destroy(); | ||
} | ||
}); | ||
|
||
// Helper function to make the test cases more readable | ||
const args = (permissions: PermissionRef[], expectations?: PermissionRef[]) => { | ||
if (expectations) { | ||
return [permissions, expectations]; | ||
} else { | ||
return [permissions]; | ||
} | ||
}; | ||
|
||
test('resolvePermissions returns empty list if undefined', async () => { | ||
const access = db.stores.accessStore as AccessStore; | ||
const result = await access.resolvePermissions( | ||
undefined as unknown as PermissionRef[], | ||
); | ||
expect(result).toStrictEqual([]); | ||
}); | ||
|
||
test('resolvePermissions returns empty list if empty list', async () => { | ||
const access = db.stores.accessStore as AccessStore; | ||
const result = await access.resolvePermissions([] as PermissionRef[]); | ||
expect(result).toStrictEqual([]); | ||
}); | ||
|
||
test.each([ | ||
args([{ id: 1 }]), | ||
args([{ id: 4, environment: 'development' }]), | ||
args([{ id: 4, name: 'should keep the id' }]), | ||
args([ | ||
{ id: 1, environment: 'development' }, | ||
{ id: 2, name: 'ignore this name' }, | ||
]), | ||
])( | ||
'resolvePermissions with permission ids (%o) returns the list unmodified', | ||
async (permissions) => { | ||
const access = db.stores.accessStore as AccessStore; | ||
const result = await access.resolvePermissions(permissions); | ||
expect(result).toStrictEqual(permissions); | ||
}, | ||
); | ||
|
||
test.each([ | ||
args( | ||
[{ name: 'CREATE_CONTEXT_FIELD' }], | ||
[{ id: 18, name: 'CREATE_CONTEXT_FIELD' }], | ||
), | ||
args( | ||
[{ name: 'CREATE_FEATURE', environment: 'development' }], | ||
[{ id: 2, name: 'CREATE_FEATURE', environment: 'development' }], | ||
), | ||
args( | ||
[ | ||
{ name: 'CREATE_CONTEXT_FIELD' }, | ||
{ name: 'CREATE_FEATURE', environment: 'development' }, | ||
], | ||
[ | ||
{ id: 18, name: 'CREATE_CONTEXT_FIELD' }, | ||
{ id: 2, name: 'CREATE_FEATURE', environment: 'development' }, | ||
], | ||
), | ||
])( | ||
'resolvePermissions with permission names (%o) will inject the ids', | ||
async (permissions, expected) => { | ||
const access = db.stores.accessStore as AccessStore; | ||
const result = await access.resolvePermissions(permissions); | ||
expect(result).toStrictEqual(expected); | ||
}, | ||
); | ||
|
||
test.each([ | ||
args( | ||
[ | ||
{ name: 'CREATE_CONTEXT_FIELD' }, | ||
{ id: 3 }, | ||
{ name: 'CREATE_FEATURE', environment: 'development' }, | ||
{ id: 15, environment: 'development' }, | ||
{ name: 'UPDATE_FEATURE', environment: 'development' }, | ||
], | ||
[ | ||
{ id: 18, name: 'CREATE_CONTEXT_FIELD' }, | ||
{ id: 3 }, | ||
{ id: 2, name: 'CREATE_FEATURE', environment: 'development' }, | ||
{ id: 15, environment: 'development' }, | ||
{ id: 7, name: 'UPDATE_FEATURE', environment: 'development' }, | ||
], | ||
), | ||
])( | ||
'resolvePermissions mixed ids and names (%o) will inject the ids where they are missing', | ||
async (permissions, expected) => { | ||
const access = db.stores.accessStore as AccessStore; | ||
const result = await access.resolvePermissions(permissions); | ||
expect(result).toStrictEqual(expected); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.