Skip to content

Commit

Permalink
Merge branch 'main' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Jul 13, 2023
2 parents c4cca15 + 2030824 commit fff6dd9
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 153 deletions.
18 changes: 16 additions & 2 deletions src/storage/filters/jsonQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,29 @@ export interface IFilterQuery {
execute(credential: W3CCredential): boolean;
}

const truthyValues = [true, 1, 'true'];
const falsyValues = [false, 0, 'false'];

const equalsComparator = (a, b) => {
if (truthyValues.includes(a) && truthyValues.includes(b)) {
return true;
}
if (falsyValues.includes(a) && falsyValues.includes(b)) {
return true;
}

return a === b;
};

export /** @type {*} - filter operators and their functions */
const comparatorOptions: { [v in FilterOperatorMethod]: FilterOperatorFunction } = {
$noop: () => true,
$eq: (a, b) => a === b,
$eq: (a, b) => equalsComparator(a, b),
$in: (a: string, b: string[]) => b.includes(a),
$nin: (a: string, b: string[]) => !b.includes(a),
$gt: (a: number, b: number) => a > b,
$lt: (a: number, b: number) => a < b,
$ne: (a, b) => a !== b
$ne: (a, b) => !equalsComparator(a, b)
};

/**
Expand Down
81 changes: 81 additions & 0 deletions tests/credentials/credential-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,87 @@ const credentialFlow = async (storage: IDataStorage) => {
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.insured': { $eq: 'true' }
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.insured': { $eq: 1 }
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.insured': { $eq: true }
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.insured': { $ne: 'false' }
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.insured': { $ne: 0 }
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.insured': { $ne: false }
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.hasOwnPackage': { $eq: 'false' }
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.hasOwnPackage': { $eq: 0 }
}
},
expected: [cred4]
},
{
query: {
allowedIssuers: ['*'],
credentialSubject: {
'country.hasOwnPackage': { $eq: false }
}
},
expected: [cred4]
}
];

Expand Down
4 changes: 3 additions & 1 deletion tests/credentials/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export const cred4 = createTestCredential({
countOfFines: 0,
country: {
name: 'Spain',
code: 'ES'
code: 'ES',
insured: true,
hasOwnPackage: 'false'
}
},
expirationDate: '2023-11-11',
Expand Down
Loading

0 comments on commit fff6dd9

Please sign in to comment.