Skip to content

Commit

Permalink
Add test for dev fixture
Browse files Browse the repository at this point in the history
Refactor message of entity validation issues
  • Loading branch information
wcalderipe committed Feb 28, 2024
1 parent 67df6d1 commit 6583f75
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ENTITIES } from '../../dev.fixture'
import { validate } from '../../util/entity.util'

describe('dev fixture', () => {
it('defines valid entities', () => {
expect(validate(ENTITIES)).toEqual({ success: true })
})
})
6 changes: 0 additions & 6 deletions packages/policy-engine-shared/src/lib/dev.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ export const ADDRESS_BOOK: AddressBookAccountEntity[] = [
chainId: 137,
classification: AccountClassification.WALLET
},
{
id: `eip155:137:${WALLET.Engineering.address}`,
address: WALLET.Engineering.address,
chainId: 137,
classification: AccountClassification.WALLET
},
{
id: `eip155:1:${WALLET.Treasury.address}`,
address: WALLET.Treasury.address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('validate', () => {
...emptyEntities,
userGroupMembers: [
{
groupId: USER_GROUP.Engineering.uid,
userId: USER.Alice.uid
groupId: USER_GROUP.Engineering.id,
userId: USER.Alice.id
}
],
users: [USER.Alice]
Expand All @@ -35,7 +35,7 @@ describe('validate', () => {
{
code: 'ENTITY_NOT_FOUND',
message:
"Couldn't create the user group member because the group test-engineering-user-group-uid is undefined"
"couldn't create the user group member because the group test-engineering-user-group-uid is undefined"
}
]
})
Expand All @@ -47,8 +47,8 @@ describe('validate', () => {
userGroups: [USER_GROUP.Engineering],
userGroupMembers: [
{
groupId: USER_GROUP.Engineering.uid,
userId: USER.Alice.uid
groupId: USER_GROUP.Engineering.id,
userId: USER.Alice.id
}
]
})
Expand All @@ -59,7 +59,7 @@ describe('validate', () => {
{
code: 'ENTITY_NOT_FOUND',
message:
"Couldn't create the user group member for group test-engineering-user-group-uid because the user test-alice-user-uid is undefined"
"couldn't create the user group member for group test-engineering-user-group-uid because the user test-alice-user-uid is undefined"
}
]
})
Expand All @@ -71,8 +71,8 @@ describe('validate', () => {
wallets: [WALLET.Engineering],
walletGroupMembers: [
{
walletId: WALLET.Engineering.uid,
groupId: WALLET_GROUP.Engineering.uid
walletId: WALLET.Engineering.id,
groupId: WALLET_GROUP.Engineering.id
}
]
})
Expand All @@ -83,7 +83,7 @@ describe('validate', () => {
{
code: 'ENTITY_NOT_FOUND',
message:
"Couldn't create the wallet group member because the group test-engineering-wallet-group-uid is undefined"
"couldn't create the wallet group member because the group test-engineering-wallet-group-uid is undefined"
}
]
})
Expand All @@ -95,8 +95,8 @@ describe('validate', () => {
walletGroups: [WALLET_GROUP.Engineering],
walletGroupMembers: [
{
walletId: WALLET.Engineering.uid,
groupId: WALLET_GROUP.Engineering.uid
walletId: WALLET.Engineering.id,
groupId: WALLET_GROUP.Engineering.id
}
]
})
Expand All @@ -107,7 +107,7 @@ describe('validate', () => {
{
code: 'ENTITY_NOT_FOUND',
message:
"Couldn't create the wallet group member for group test-engineering-wallet-group-uid because the wallet eip155:eoa:0x22228d0504d4f3363a5b7fda1f5fff1c7bca8ad4 is undefined"
"couldn't create the wallet group member for group test-engineering-wallet-group-uid because the wallet eip155:eoa:0x22228d0504d4f3363a5b7fda1f5fff1c7bca8ad4 is undefined"
}
]
})
Expand All @@ -119,8 +119,8 @@ describe('validate', () => {
wallets: [WALLET.Engineering],
userWallets: [
{
userId: USER.Alice.uid,
walletId: WALLET.Engineering.uid
userId: USER.Alice.id,
walletId: WALLET.Engineering.id
}
]
})
Expand All @@ -130,7 +130,7 @@ describe('validate', () => {
issues: [
{
code: 'ENTITY_NOT_FOUND',
message: `Couldn't assign the wallet ${WALLET.Engineering.uid} because the user ${USER.Alice.uid} is undefined`
message: `couldn't assign the wallet ${WALLET.Engineering.id} because the user ${USER.Alice.id} is undefined`
}
]
})
Expand All @@ -142,8 +142,8 @@ describe('validate', () => {
users: [USER.Alice],
userWallets: [
{
userId: USER.Alice.uid,
walletId: WALLET.Engineering.uid
userId: USER.Alice.id,
walletId: WALLET.Engineering.id
}
]
})
Expand All @@ -153,7 +153,7 @@ describe('validate', () => {
issues: [
{
code: 'ENTITY_NOT_FOUND',
message: `Couldn't assign the wallet ${WALLET.Engineering.uid} because it's undefined`
message: `couldn't assign the wallet ${WALLET.Engineering.id} because it's undefined`
}
]
})
Expand All @@ -172,7 +172,7 @@ describe('validate', () => {
issues: [
{
code: 'UNIQUE_IDENTIFIER_DUPLICATION',
message: `The address book account ${ADDRESS_BOOK[0].uid} is duplicated`
message: `the address book account ${ADDRESS_BOOK[0].id} is duplicated`
}
]
})
Expand All @@ -189,7 +189,7 @@ describe('validate', () => {
issues: [
{
code: 'UNIQUE_IDENTIFIER_DUPLICATION',
message: `The credential ${CREDENTIAL.Alice.uid} is duplicated`
message: `the credential ${CREDENTIAL.Alice.id} is duplicated`
}
]
})
Expand All @@ -206,7 +206,7 @@ describe('validate', () => {
issues: [
{
code: 'UNIQUE_IDENTIFIER_DUPLICATION',
message: `The token ${TOKEN.usdc1.uid} is duplicated`
message: `the token ${TOKEN.usdc1.id} is duplicated`
}
]
})
Expand All @@ -223,7 +223,7 @@ describe('validate', () => {
issues: [
{
code: 'UNIQUE_IDENTIFIER_DUPLICATION',
message: `The user group ${USER_GROUP.Engineering.uid} is duplicated`
message: `the user group ${USER_GROUP.Engineering.id} is duplicated`
}
]
})
Expand All @@ -240,7 +240,7 @@ describe('validate', () => {
issues: [
{
code: 'UNIQUE_IDENTIFIER_DUPLICATION',
message: `The user ${USER.Alice.uid} is duplicated`
message: `the user ${USER.Alice.id} is duplicated`
}
]
})
Expand All @@ -257,7 +257,7 @@ describe('validate', () => {
issues: [
{
code: 'UNIQUE_IDENTIFIER_DUPLICATION',
message: `The wallet group ${WALLET_GROUP.Engineering.uid} is duplicated`
message: `the wallet group ${WALLET_GROUP.Engineering.id} is duplicated`
}
]
})
Expand All @@ -274,21 +274,21 @@ describe('validate', () => {
issues: [
{
code: 'UNIQUE_IDENTIFIER_DUPLICATION',
message: `The wallet ${WALLET.Engineering.uid} is duplicated`
message: `the wallet ${WALLET.Engineering.id} is duplicated`
}
]
})
})
})

describe('uid format', () => {
it('fails when address book account uid is not an account id', () => {
describe('id format', () => {
it('fails when address book account id is not an account id', () => {
const invalidAccountId = '16aba381-c54a-4f72-89bd-bd1e7c46ed29'
const result = validate({
...emptyEntities,
addressBook: [
{
uid: invalidAccountId,
id: invalidAccountId,
address: WALLET.Engineering.address,
chainId: 137,
classification: AccountClassification.WALLET
Expand All @@ -302,20 +302,20 @@ describe('validate', () => {
issues: [
{
code: 'INVALID_UID_FORMAT',
message: `address book account uid ${invalidAccountId} is not a valid account id`
message: `address book account id ${invalidAccountId} is not a valid account id`
}
]
})
})

it('fails when token uid is not an asset id', () => {
it('fails when token id is not an asset id', () => {
const invalidAccountId = '16aba381-c54a-4f72-89bd-bd1e7c46ed29'
const result = validate({
...emptyEntities,
tokens: [
{
...TOKEN.usdc1,
uid: invalidAccountId
id: invalidAccountId
},
TOKEN.usdc137
]
Expand All @@ -326,7 +326,7 @@ describe('validate', () => {
issues: [
{
code: 'INVALID_UID_FORMAT',
message: `token uid ${invalidAccountId} is not a valid asset id`
message: `token id ${invalidAccountId} is not a valid asset id`
}
]
})
Expand Down
30 changes: 15 additions & 15 deletions packages/policy-engine-shared/src/lib/util/entity.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const validateUserGroupMemberIntegrity: Validator = (entities: Entities): Valida
.filter(({ userId }) => !users[userId])
.map(({ userId, groupId }) => ({
code: 'ENTITY_NOT_FOUND',
message: `Couldn't create the user group member for group ${groupId} because the user ${userId} is undefined`
message: `couldn't create the user group member for group ${groupId} because the user ${userId} is undefined`
}))

const groupIssues: ValidationIssue[] = entities.userGroupMembers
.filter(({ groupId }) => !userGroups[groupId])
.map(({ groupId }) => ({
code: 'ENTITY_NOT_FOUND',
message: `Couldn't create the user group member because the group ${groupId} is undefined`
message: `couldn't create the user group member because the group ${groupId} is undefined`
}))

return [...userIssues, ...groupIssues]
Expand All @@ -44,14 +44,14 @@ const validateWalletGroupMemberIntegrity: Validator = (entities: Entities): Vali
.filter(({ walletId }) => !wallets[walletId])
.map(({ walletId, groupId }) => ({
code: 'ENTITY_NOT_FOUND',
message: `Couldn't create the wallet group member for group ${groupId} because the wallet ${walletId} is undefined`
message: `couldn't create the wallet group member for group ${groupId} because the wallet ${walletId} is undefined`
}))

const groupIssues: ValidationIssue[] = entities.walletGroupMembers
.filter(({ groupId }) => !walletGroups[groupId])
.map(({ groupId }) => ({
code: 'ENTITY_NOT_FOUND',
message: `Couldn't create the wallet group member because the group ${groupId} is undefined`
message: `couldn't create the wallet group member because the group ${groupId} is undefined`
}))

return [...walletIssues, ...groupIssues]
Expand All @@ -65,14 +65,14 @@ const validateUserWalletIntegrity: Validator = (entities: Entities): ValidationI
.filter(({ userId }) => !users[userId])
.map(({ userId, walletId }) => ({
code: 'ENTITY_NOT_FOUND',
message: `Couldn't assign the wallet ${walletId} because the user ${userId} is undefined`
message: `couldn't assign the wallet ${walletId} because the user ${userId} is undefined`
}))

const walletIssues: ValidationIssue[] = entities.userWallets
.filter(({ walletId }) => !wallets[walletId])
.map(({ walletId }) => ({
code: 'ENTITY_NOT_FOUND',
message: `Couldn't assign the wallet ${walletId} because it's undefined`
message: `couldn't assign the wallet ${walletId} because it's undefined`
}))

return [...userIssues, ...walletIssues]
Expand All @@ -92,13 +92,13 @@ const validateUniqueIdDuplication: Validator = (entities: Entities): ValidationI
}

return flatten([
findIssues(entities.addressBook, (id) => `The address book account ${id} is duplicated`),
findIssues(entities.credentials, (id) => `The credential ${id} is duplicated`),
findIssues(entities.tokens, (id) => `The token ${id} is duplicated`),
findIssues(entities.userGroups, (id) => `The user group ${id} is duplicated`),
findIssues(entities.users, (id) => `The user ${id} is duplicated`),
findIssues(entities.walletGroups, (id) => `The wallet group ${id} is duplicated`),
findIssues(entities.wallets, (id) => `The wallet ${id} is duplicated`)
findIssues(entities.addressBook, (id) => `the address book account ${id} is duplicated`),
findIssues(entities.credentials, (id) => `the credential ${id} is duplicated`),
findIssues(entities.tokens, (id) => `the token ${id} is duplicated`),
findIssues(entities.userGroups, (id) => `the user group ${id} is duplicated`),
findIssues(entities.users, (id) => `the user ${id} is duplicated`),
findIssues(entities.walletGroups, (id) => `the wallet group ${id} is duplicated`),
findIssues(entities.wallets, (id) => `the wallet ${id} is duplicated`)
])
}

Expand All @@ -108,7 +108,7 @@ const validateAddressBookUniqueIdFormat: Validator = (entities: Entities): Valid
.map(({ id: uid }) => {
return {
code: 'INVALID_UID_FORMAT',
message: `address book account uid ${uid} is not a valid account id`
message: `address book account id ${uid} is not a valid account id`
}
})
}
Expand All @@ -119,7 +119,7 @@ const validateTokenUniqueIdFormat: Validator = (entities: Entities): ValidationI
.map(({ id: uid }) => {
return {
code: 'INVALID_UID_FORMAT',
message: `token uid ${uid} is not a valid asset id`
message: `token id ${uid} is not a valid asset id`
}
})
}
Expand Down

0 comments on commit 6583f75

Please sign in to comment.