Fix number ranges after tenant import
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 45s
Build and Push Docker Images / build-frontend (push) Successful in 25s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-api (push) Successful in 23s
Build and Push Docker Images / build-central-services-admin (push) Successful in 24s
Build and Push Docker Images / build-docs (push) Successful in 24s
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 45s
Build and Push Docker Images / build-frontend (push) Successful in 25s
Build and Push Docker Images / build-website (push) Successful in 23s
Build and Push Docker Images / build-central-services-api (push) Successful in 23s
Build and Push Docker Images / build-central-services-admin (push) Successful in 24s
Build and Push Docker Images / build-docs (push) Successful in 24s
This commit is contained in:
48
backend/tests/tenantImportNumberRanges.test.ts
Normal file
48
backend/tests/tenantImportNumberRanges.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
|
||||
import { restoreImportedTenantNumberRanges } from "../src/utils/tenantImportNumberRanges"
|
||||
|
||||
test("restores number ranges when importing into an existing target tenant", async () => {
|
||||
const queries: { query: string, values: unknown[] }[] = []
|
||||
const numberRanges = {
|
||||
invoices: { prefix: "RE-", suffix: "", nextNumber: 4712 },
|
||||
}
|
||||
const client = {
|
||||
async query(query: string, values: unknown[]) {
|
||||
queries.push({ query, values })
|
||||
return { rowCount: 1 }
|
||||
},
|
||||
}
|
||||
|
||||
const updated = await restoreImportedTenantNumberRanges(client, {
|
||||
tenantId: 42,
|
||||
tables: {
|
||||
tenants: [{ id: 42, name: "Zieltenant", numberRanges }],
|
||||
},
|
||||
})
|
||||
|
||||
assert.equal(updated, 1)
|
||||
assert.deepEqual(queries, [{
|
||||
query: `update "tenants" set "numberRanges" = $1::jsonb where "id" = $2`,
|
||||
values: [JSON.stringify(numberRanges), 42],
|
||||
}])
|
||||
})
|
||||
|
||||
test("does not overwrite number ranges when the export contains none", async () => {
|
||||
let queryCalled = false
|
||||
const client = {
|
||||
async query() {
|
||||
queryCalled = true
|
||||
return { rowCount: 1 }
|
||||
},
|
||||
}
|
||||
|
||||
const updated = await restoreImportedTenantNumberRanges(client, {
|
||||
tenantId: 42,
|
||||
tables: { tenants: [{ id: 42, name: "Zieltenant" }] },
|
||||
})
|
||||
|
||||
assert.equal(updated, 0)
|
||||
assert.equal(queryCalled, false)
|
||||
})
|
||||
Reference in New Issue
Block a user