Kundeninventar-Nummern kollisionsfrei vergeben
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 21s
Build and Push Docker Images / build-website (push) Successful in 21s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-docs (push) Successful in 21s
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 21s
Build and Push Docker Images / build-website (push) Successful in 21s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-docs (push) Successful in 21s
This commit is contained in:
50
backend/tests/numberRangeAvailability.test.ts
Normal file
50
backend/tests/numberRangeAvailability.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
|
||||
import { useNextNumberRangeNumber } from "../src/utils/functions"
|
||||
|
||||
test("number range skips identifiers that are already in use", async () => {
|
||||
const tenant = {
|
||||
id: 7,
|
||||
numberRanges: {
|
||||
customerinventoryitems: {
|
||||
prefix: "KIA-",
|
||||
suffix: "",
|
||||
nextNumber: 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
let savedNumberRanges: any = null
|
||||
|
||||
const tx = {
|
||||
execute: async () => undefined,
|
||||
select: () => ({
|
||||
from: () => ({
|
||||
where: async () => [tenant],
|
||||
}),
|
||||
}),
|
||||
update: () => ({
|
||||
set: (data: any) => ({
|
||||
where: async () => {
|
||||
savedNumberRanges = data.numberRanges
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}
|
||||
const server = {
|
||||
db: {
|
||||
transaction: async (callback: (transaction: typeof tx) => Promise<any>) => callback(tx),
|
||||
},
|
||||
} as any
|
||||
const occupied = new Set(["KIA-1000", "KIA-1001"])
|
||||
|
||||
const result = await useNextNumberRangeNumber(
|
||||
server,
|
||||
tenant.id,
|
||||
"customerinventoryitems",
|
||||
async (candidate) => !occupied.has(candidate)
|
||||
)
|
||||
|
||||
assert.equal(result.usedNumber, "KIA-1002")
|
||||
assert.equal(savedNumberRanges.customerinventoryitems.nextNumber, 1003)
|
||||
})
|
||||
Reference in New Issue
Block a user