|
| 1 | +import * as mocha from "mocha"; |
| 2 | +import * as assert from "assert"; |
| 3 | +import { User, Company, Order } from "../Assets/Entities"; |
| 4 | +import { testContext, disposeTestDocumentStore } from "../Utils/TestUtil"; |
| 5 | + |
| 6 | +import { |
| 7 | + RavenErrorType, |
| 8 | + IDocumentStore, |
| 9 | + SeedIdentityForCommand, |
| 10 | + GetIdentitiesOperation, |
| 11 | +} from "../../src"; |
| 12 | + |
| 13 | +describe("RDBC-265", function () { |
| 14 | + |
| 15 | + let store: IDocumentStore; |
| 16 | + |
| 17 | + beforeEach(async function () { |
| 18 | + store = await testContext.getDocumentStore(); |
| 19 | + }); |
| 20 | + |
| 21 | + afterEach(async () => |
| 22 | + await disposeTestDocumentStore(store)); |
| 23 | + |
| 24 | + it("sets identity back to 0 only when forced", async () => { |
| 25 | + { |
| 26 | + const session = store.openSession(); |
| 27 | + const user = Object.assign(new User(), { lastName: "Adi" }); |
| 28 | + await session.store(user, "users|"); |
| 29 | + await session.saveChanges(); |
| 30 | + assert.strictEqual(user.id, "users/1"); |
| 31 | + } |
| 32 | + |
| 33 | + let identities = await store.maintenance.send(new GetIdentitiesOperation()); |
| 34 | + assert.strictEqual(identities["users|"], 1); |
| 35 | + |
| 36 | + let command = new SeedIdentityForCommand("users", 0); |
| 37 | + await store.getRequestExecutor().execute(command); |
| 38 | + |
| 39 | + identities = await store.maintenance.send(new GetIdentitiesOperation()); |
| 40 | + assert.strictEqual(identities["users|"], 1); |
| 41 | + |
| 42 | + command = new SeedIdentityForCommand("users", 0, true); |
| 43 | + await store.getRequestExecutor().execute(command); |
| 44 | + |
| 45 | + identities = await store.maintenance.send(new GetIdentitiesOperation()); |
| 46 | + assert.strictEqual(identities["users|"], 0); |
| 47 | + |
| 48 | + // the below won't work however |
| 49 | + // due to https://github.com/ravendb/ravendb/blob/v4.1/test/SlowTests/Issues/RavenDB_9576.cs#L14 |
| 50 | + // { |
| 51 | + // const session = store.openSession(); |
| 52 | + // const user = Object.assign(new User(), { lastName: "Avivi" }); |
| 53 | + // await session.store(user, "users|"); |
| 54 | + // await session.saveChanges(); |
| 55 | + // assert.strictEqual(user.id, "users/1"); |
| 56 | + // } |
| 57 | + }); |
| 58 | +}); |
0 commit comments