Skip to content

Commit e8ceb21

Browse files
committed
add advanced patch sample test
1 parent 04c2f1f commit e8ceb21

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,11 @@ const suggestionQueryResult = await session.query({ collection: "users" })
740740
### Advanced patching
741741
```javascript
742742
session.advanced.increment("users/1", "age", 1);
743+
// increments *age* field by 1
744+
743745
session.advanced.patch("users/1", "underAge", false);
746+
// sets *underAge* field to *false*
747+
744748
await session.saveChanges();
745749
```
746750

test/Documents/ReadmeSamples.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,31 @@ describe("Readme query samples", function () {
430430

431431
});
432432

433+
it("can use advanced.patch", async () => {
434+
store.conventions.findCollectionNameForObjectLiteral = () => "users";
435+
436+
{
437+
const session = store.openSession();
438+
await session.store({ name: "Matilda", age: 17, underAge: true }, "users/1");
439+
await session.saveChanges();
440+
}
441+
442+
{
443+
const session = store.openSession();
444+
session.advanced.increment("users/1", "age", 1);
445+
session.advanced.patch("users/1", "underAge", false);
446+
await session.saveChanges();
447+
}
448+
449+
{
450+
const session = store.openSession();
451+
const loaded: any = await session.load("users/1");
452+
assert.strictEqual(loaded.underAge, false);
453+
assert.strictEqual(loaded.age, 18);
454+
assert.strictEqual(loaded.name, "Matilda");
455+
}
456+
});
457+
433458
describe("with revisions set up", function() {
434459

435460
beforeEach(async () => testContext.setupRevisions(store, false, 5));

0 commit comments

Comments
 (0)