Skip to content

Commit

Permalink
add tests for deleted field and {enc,dec} conversions
Browse files Browse the repository at this point in the history
Tomás Ciccola committed Sep 25, 2023
1 parent e67f5c9 commit 9166171
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/decode-conversions.ts
Original file line number Diff line number Diff line change
@@ -56,7 +56,12 @@ export const convertObservation: ConvertFunction<'observation'> = (
...rest,
refs: message.refs?.map(({ id }) => ({ id: id.toString('hex') })),
attachments: message.attachments?.map(({ driveId, name, type, hash }) => {
return { driveId: driveId.toString('hex'), name, type, hash: hash.toString('hex') }
return {
driveId: driveId.toString('hex'),
name,
type,
hash: hash.toString('hex'),
}
}),
tags: convertTags(message.tags),
metadata: message.metadata || {},
@@ -251,5 +256,6 @@ function convertCommon(
createdAt: common.createdAt,
updatedAt: common.updatedAt,
createdBy: common.createdBy.toString('hex'),
deleted: common.deleted || undefined,
}
}
1 change: 1 addition & 0 deletions src/lib/encode-conversions.ts
Original file line number Diff line number Diff line change
@@ -141,6 +141,7 @@ function convertCommon(
updatedAt: common.updatedAt,
createdBy: Buffer.from(common.createdBy, 'hex'),
links: common.links.map((link) => parseVersionId(link)),
deleted: common.deleted,
}
}

19 changes: 19 additions & 0 deletions test/fixtures/bad-docs.js
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ export const badDocs = [
schemaName: 'observOtion',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
refs: [],
attachments: [],
@@ -32,9 +33,27 @@ export const badDocs = [
schemaName: 'role',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
roleId: '',
fromIndex: 4,
},
},
{
text: 'doc with invalid value for `deleted` field',
doc: {
docId: cachedValues.docId,
versionId: cachedValues.versionId,
schemaName: 'observation',
createdAt: cachedValues.createdAt,
updatedAt: cachedValues.updatedAt,
createdBy: cachedValues.createdBy,
links: [],
refs: [],
attachments: [],
tags: {},
metadata: {},
deleted: false,
},
},
]

0 comments on commit 9166171

Please sign in to comment.