mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 17:49:09 +00:00
Reach parity with last web iteration. (#162)
* feat: add Api and Session contexts * feat(web): add machinery/new-session * feat(web): add servers page * chore(web): AppRouter spacing/ordering * feat(web): add picker, missing update-roles call for now * feat(web): add picker saves * chore: add roleTransactions tests * feat(web): add auth/login
This commit is contained in:
parent
f65779f925
commit
cd448b56c9
20 changed files with 567 additions and 7 deletions
25
packages/web/src/utils/roleTransactions.spec.ts
Normal file
25
packages/web/src/utils/roleTransactions.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { RoleTransaction, TransactionType } from '@roleypoly/types';
|
||||
import { makeRoleTransactions } from './roleTransactions';
|
||||
|
||||
it('creates a transactional diff of two sets of roles', () => {
|
||||
const currentRoles = ['aaa', 'bbb', 'ccc', 'ddd'];
|
||||
const nextRoles = ['bbb', 'ccc', 'ddd', 'eee', 'fff']; // removes aaa, adds eee + fff
|
||||
|
||||
const transactions = makeRoleTransactions(currentRoles, nextRoles);
|
||||
expect(transactions).toEqual(
|
||||
expect.arrayContaining<RoleTransaction>([
|
||||
{
|
||||
id: 'aaa',
|
||||
action: TransactionType.Remove,
|
||||
},
|
||||
{
|
||||
id: 'fff',
|
||||
action: TransactionType.Add,
|
||||
},
|
||||
{
|
||||
id: 'eee',
|
||||
action: TransactionType.Add,
|
||||
},
|
||||
])
|
||||
);
|
||||
});
|
30
packages/web/src/utils/roleTransactions.ts
Normal file
30
packages/web/src/utils/roleTransactions.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { Role, RoleTransaction, TransactionType } from '@roleypoly/types';
|
||||
|
||||
export const makeRoleTransactions = (
|
||||
oldRoles: Role['id'][],
|
||||
newRoles: Role['id'][]
|
||||
): RoleTransaction[] => {
|
||||
const transactions: RoleTransaction[] = [];
|
||||
|
||||
// Removes: old roles not in new roles
|
||||
for (let oldID of oldRoles) {
|
||||
if (!newRoles.includes(oldID)) {
|
||||
transactions.push({
|
||||
id: oldID,
|
||||
action: TransactionType.Remove,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Adds: new roles not in old roles
|
||||
for (let newID of newRoles) {
|
||||
if (!oldRoles.includes(newID)) {
|
||||
transactions.push({
|
||||
id: newID,
|
||||
action: TransactionType.Add,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return transactions;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue