From 8ea2c4a17f8658d72c1ed479246dacb460b9ea2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Ciccola?= Date: Tue, 26 Sep 2023 14:05:19 -0300 Subject: [PATCH] make `deleted` required, fix tests --- proto/common/v1.proto | 2 +- schema/common/v1.json | 6 +++--- src/lib/decode-conversions.ts | 2 +- test/fixtures/bad-docs.js | 17 +---------------- test/fixtures/good-docs-completed.js | 7 +++++++ test/fixtures/good-docs-minimal.js | 7 +++++++ 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/proto/common/v1.proto b/proto/common/v1.proto index 31b0d6d..d27c2e7 100644 --- a/proto/common/v1.proto +++ b/proto/common/v1.proto @@ -16,7 +16,7 @@ message Common_1 { google.protobuf.Timestamp updatedAt = 4 [(required) = true]; // 32-byte hash of the discovery key of a core bytes createdBy = 5 [(required) = true]; - optional bool deleted = 6; + bool deleted = 6; } /* ignored fields and differences from common.json jsonSchema * id is a byte buffer here and a string in jsonSchema diff --git a/schema/common/v1.json b/schema/common/v1.json index a1794e6..0f439b4 100644 --- a/schema/common/v1.json +++ b/schema/common/v1.json @@ -41,8 +41,7 @@ }, "deleted": { "description": "Indicates whether the document has been deleted", - "type": "boolean", - "const": true + "type": "boolean" } }, "required": [ @@ -52,6 +51,7 @@ "updatedAt", "links", "versionId", - "createdBy" + "createdBy", + "deleted" ] } diff --git a/src/lib/decode-conversions.ts b/src/lib/decode-conversions.ts index 192b8c4..d4187a3 100644 --- a/src/lib/decode-conversions.ts +++ b/src/lib/decode-conversions.ts @@ -256,6 +256,6 @@ function convertCommon( createdAt: common.createdAt, updatedAt: common.updatedAt, createdBy: common.createdBy.toString('hex'), - deleted: common.deleted || undefined, + deleted: common.deleted, } } diff --git a/test/fixtures/bad-docs.js b/test/fixtures/bad-docs.js index 753a1ef..018af7c 100644 --- a/test/fixtures/bad-docs.js +++ b/test/fixtures/bad-docs.js @@ -22,6 +22,7 @@ export const badDocs = [ attachments: [], tags: {}, metadata: {}, + deleted: false, }, }, { @@ -37,22 +38,6 @@ export const badDocs = [ 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, }, }, diff --git a/test/fixtures/good-docs-completed.js b/test/fixtures/good-docs-completed.js index 3b00265..7d206f4 100644 --- a/test/fixtures/good-docs-completed.js +++ b/test/fixtures/good-docs-completed.js @@ -66,6 +66,7 @@ export const goodDocsCompleted = [ networkAvailable: false, }, }, + deleted: false, }, expected: {}, }, @@ -86,6 +87,7 @@ export const goodDocsCompleted = [ relation: cachedValues.defaultPresets.point, }, name: 'myProject', + deleted: false, }, expected: {}, }, @@ -110,6 +112,7 @@ export const goodDocsCompleted = [ value: 'somePrimitiveTagValue', }, ], + deleted: false, }, expected: {}, }, @@ -137,6 +140,7 @@ export const goodDocsCompleted = [ fieldIds: cachedValues.fieldIds, iconId: cachedValues.iconId, terms: ['imastring'], + deleted: false, }, expected: {}, }, @@ -151,6 +155,7 @@ export const goodDocsCompleted = [ links: [], roleId: '6fd029a78243', fromIndex: 5, + deleted: false, }, expected: {}, }, @@ -164,6 +169,7 @@ export const goodDocsCompleted = [ createdBy: cachedValues.createdBy, links: [], name: 'my device name', + deleted: false, }, expected: {}, }, @@ -189,6 +195,7 @@ export const goodDocsCompleted = [ blobIndex: Buffer.from('blobIndex'), }, identitySignature: Buffer.from('identity'), + deleted: false, }, expected: {}, }, diff --git a/test/fixtures/good-docs-minimal.js b/test/fixtures/good-docs-minimal.js index 1ea78da..d1b2b82 100644 --- a/test/fixtures/good-docs-minimal.js +++ b/test/fixtures/good-docs-minimal.js @@ -24,6 +24,7 @@ export const goodDocsMinimal = [ attachments: [], tags: {}, metadata: {}, + deleted: false, }, expected: {}, }, @@ -36,6 +37,7 @@ export const goodDocsMinimal = [ updatedAt: cachedValues.updatedAt, createdBy: cachedValues.createdBy, links: [], + deleted: false, }, expected: {}, }, @@ -51,6 +53,7 @@ export const goodDocsMinimal = [ tagKey: 'myTagKey', label: 'my label', type: 'text', + deleted: false, }, expected: {}, }, @@ -70,6 +73,7 @@ export const goodDocsMinimal = [ removeTags: {}, fieldIds: [], terms: [], + deleted: false, }, expected: {}, }, @@ -84,6 +88,7 @@ export const goodDocsMinimal = [ links: [], roleId: '3b0104e370f9', fromIndex: 5, + deleted: false, }, expected: {}, }, @@ -97,6 +102,7 @@ export const goodDocsMinimal = [ createdBy: cachedValues.createdBy, links: [], name: 'my device name', + deleted: false, }, expected: {}, }, @@ -122,6 +128,7 @@ export const goodDocsMinimal = [ blobIndex: Buffer.from('blobIndex'), }, identitySignature: Buffer.from('identity'), + deleted: false, }, expected: {}, },