Skip to content

Commit

Permalink
Merge pull request #30 from docknetwork/fix/falsey-attributes
Browse files Browse the repository at this point in the history
Fix gather of falsey attributes
  • Loading branch information
cykoder authored Dec 19, 2024
2 parents fe7f4cd + 35fc94b commit af13137
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@docknetwork/prettyvc",
"description": "Render pretty verifiable credentials",
"version": "1.3.16",
"version": "1.3.17",
"main": "lib/index.js",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ export function objectToAttributesArray(object, result = [], parentName = '', pa
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = object[key];
if (value) {
if (typeof value === 'object') {
if (value !== undefined) {
if (value && typeof value === 'object') {
objectToAttributesArray(value, result, `${key} `, `${parentProperty ? `${parentProperty}` : ''}${key}.`);
} else {
result.push({
Expand Down
4 changes: 2 additions & 2 deletions src/templates/credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function TemplateCredential({
const attributesTableRows = attributes.map((attribute) => (`
<tr>
<td><strong>${sanitize(attribute.name)}</strong></td>
<td>${sanitize(attribute.value)}</td>
<td>${sanitize(attribute.value === 0 ? '0' : attribute.value)}</td>
</tr>
`)).join('\n');
return `
Expand Down Expand Up @@ -49,7 +49,7 @@ export default function TemplateCredential({
</div>
` : ''}
<div class="prettyVC-diploma-footersubject">
<strong>${sanitize(title)}</strong>
<strong>${sanitize(title.substr(0, 42))}</strong>
<span>Issued on: ${sanitize(date)}</span>
${expiryDate ? `
<span>Expire at: ${sanitize(expiryDate)}</span>
Expand Down
26 changes: 26 additions & 0 deletions tests/get-vc-data.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
getVCData,
} from '../src/index';

describe('getVCData', () => {
test('includes falsey attributes', async () => {
const template = await getVCData({
type: ['VerifiableCredential'],
credentialSubject: {
id: 'testid',
attribEmpty: '',
attribZero: 0,
attribOne: 1,
},
issuer: 'test',
issuanceDate: new Date().toISOString(),
});

expect(template.attributes).toEqual([
{ name: 'Id', property: 'id', value: 'testid' },
{ name: 'Attrib Empty', property: 'attribEmpty', value: '' },
{ name: 'Attrib Zero', property: 'attribZero', value: 0 },
{ name: 'Attrib One', property: 'attribOne', value: 1 },
]);
});
});

0 comments on commit af13137

Please sign in to comment.