|
1 | 1 | /*!
|
2 |
| - * Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved. |
| 2 | + * Copyright (c) 2018-2025 Digital Bazaar, Inc. All rights reserved. |
3 | 3 | */
|
4 | 4 | import * as brEdvStorage from '@bedrock/edv-storage';
|
5 | 5 | import * as database from '@bedrock/mongodb';
|
@@ -39,6 +39,40 @@ describe('docs.update API', () => {
|
39 | 39 | });
|
40 | 40 | record.doc.should.eql(doc);
|
41 | 41 | });
|
| 42 | + it('should update a document and remove its attributes', async () => { |
| 43 | + // add doc |
| 44 | + await brEdvStorage.docs.update({ |
| 45 | + edvId: mockEdvId, doc: mockData.docWithUniqueAttributes |
| 46 | + }); |
| 47 | + |
| 48 | + // ensure attributes exist |
| 49 | + { |
| 50 | + const record = await collection.findOne({ |
| 51 | + localEdvId: localMockEdvId, |
| 52 | + 'doc.id': mockData.docWithUniqueAttributes.id |
| 53 | + }); |
| 54 | + record.doc.sequence.should.equal(0); |
| 55 | + should.exist(record.attributes); |
| 56 | + should.exist(record.uniqueAttributes); |
| 57 | + } |
| 58 | + |
| 59 | + // update doc to remove attributes |
| 60 | + const doc = {...mockData.docWithUniqueAttributes, sequence: 1}; |
| 61 | + doc.indexed = structuredClone(doc.indexed); |
| 62 | + doc.indexed[0].attributes = []; |
| 63 | + await brEdvStorage.docs.update({edvId: mockEdvId, doc}); |
| 64 | + |
| 65 | + // ensure attributes have been cleared |
| 66 | + { |
| 67 | + const record = await collection.findOne({ |
| 68 | + localEdvId: localMockEdvId, |
| 69 | + 'doc.id': mockData.docWithUniqueAttributes.id |
| 70 | + }); |
| 71 | + record.doc.sequence.should.equal(1); |
| 72 | + should.not.exist(record.attributes); |
| 73 | + should.not.exist(record.uniqueAttributes); |
| 74 | + } |
| 75 | + }); |
42 | 76 | it('should fail to update a document with max safe sequence', async () => {
|
43 | 77 | let error;
|
44 | 78 | const doc = {...mockData.doc1, sequence: Number.MAX_SAFE_INTEGER};
|
|
0 commit comments