@tellescope/sdk 1.68.6 → 1.68.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/sdk.js +2 -2
- package/lib/cjs/sdk.js.map +1 -1
- package/lib/cjs/tests/tests.d.ts.map +1 -1
- package/lib/cjs/tests/tests.js +231 -74
- package/lib/cjs/tests/tests.js.map +1 -1
- package/lib/esm/sdk.js +2 -2
- package/lib/esm/sdk.js.map +1 -1
- package/lib/esm/session.d.ts +0 -1
- package/lib/esm/session.d.ts.map +1 -1
- package/lib/esm/tests/tests.d.ts.map +1 -1
- package/lib/esm/tests/tests.js +221 -64
- package/lib/esm/tests/tests.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/sdk.ts +2 -2
- package/src/tests/tests.ts +170 -1
- package/test_generated.pdf +0 -0
package/src/tests/tests.ts
CHANGED
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
CreateTicketAssignmentStrategy,
|
|
16
16
|
FormResponseValue,
|
|
17
17
|
ModelName,
|
|
18
|
+
RoundRobinAssignmentInfo,
|
|
19
|
+
User,
|
|
18
20
|
} from "@tellescope/types-models"
|
|
19
21
|
|
|
20
22
|
import {
|
|
@@ -30,7 +32,7 @@ import {
|
|
|
30
32
|
} from "@tellescope/validation"
|
|
31
33
|
|
|
32
34
|
import { Session, APIQuery, EnduserSession } from "../sdk"
|
|
33
|
-
import {
|
|
35
|
+
import { weighted_round_robin } from "@tellescope/utilities"
|
|
34
36
|
import { DEFAULT_OPERATIONS, PLACEHOLDER_ID } from "@tellescope/constants"
|
|
35
37
|
import {
|
|
36
38
|
schema,
|
|
@@ -5788,6 +5790,8 @@ const TRACK_OPEN_IMAGE = Buffer.from(
|
|
|
5788
5790
|
);
|
|
5789
5791
|
|
|
5790
5792
|
const validate_schema = () => {
|
|
5793
|
+
log_header("Validate Schema")
|
|
5794
|
+
|
|
5791
5795
|
const endpoints = new Set<string>([])
|
|
5792
5796
|
|
|
5793
5797
|
let modelName = undefined! as ModelName
|
|
@@ -5815,6 +5819,169 @@ const validate_schema = () => {
|
|
|
5815
5819
|
}
|
|
5816
5820
|
}
|
|
5817
5821
|
|
|
5822
|
+
const test_weighted_round_robin = async () => {
|
|
5823
|
+
log_header("Test validate_weighted_round_robin")
|
|
5824
|
+
|
|
5825
|
+
const testUsers: Pick<User, 'id' | 'ticketAssignmentPriority'>[] = [
|
|
5826
|
+
{ id: '0', ticketAssignmentPriority: undefined }, // will default to 5
|
|
5827
|
+
{ id: '1', ticketAssignmentPriority: 1 },
|
|
5828
|
+
{ id: '2', ticketAssignmentPriority: 2 },
|
|
5829
|
+
{ id: '3', ticketAssignmentPriority: 3 },
|
|
5830
|
+
]
|
|
5831
|
+
const userIds = testUsers.map(u => u.id)
|
|
5832
|
+
const testAssignments: RoundRobinAssignmentInfo[] = testUsers.map((u, i) => ({
|
|
5833
|
+
id: i.toString(),
|
|
5834
|
+
key: 'test',
|
|
5835
|
+
timestamp: Date.now() - 1000,
|
|
5836
|
+
userId: u.id,
|
|
5837
|
+
}))
|
|
5838
|
+
|
|
5839
|
+
await async_test(
|
|
5840
|
+
`Both empty`,
|
|
5841
|
+
async () => weighted_round_robin({ assignments: [], users: [] }),
|
|
5842
|
+
{ onResult: r => r.selected === undefined }
|
|
5843
|
+
)
|
|
5844
|
+
await async_test(
|
|
5845
|
+
`Single user, empty assignment`,
|
|
5846
|
+
async () => weighted_round_robin({ assignments: [], users: [testUsers[0]] }),
|
|
5847
|
+
{ onResult: r => r.selected === testUsers[0].id }
|
|
5848
|
+
)
|
|
5849
|
+
await async_test(
|
|
5850
|
+
`Both singletons`,
|
|
5851
|
+
async () => weighted_round_robin({ assignments: [testAssignments[0]], users: [testUsers[0]] }),
|
|
5852
|
+
{ onResult: r => r.selected === testUsers[0].id }
|
|
5853
|
+
)
|
|
5854
|
+
|
|
5855
|
+
const run_assignment_simulation = ({
|
|
5856
|
+
iterations,
|
|
5857
|
+
expectedSelections,
|
|
5858
|
+
users=testUsers,
|
|
5859
|
+
title=`Simulation ${iterations}`,
|
|
5860
|
+
} : {
|
|
5861
|
+
expectedSelections: string[],
|
|
5862
|
+
iterations: number,
|
|
5863
|
+
users?: typeof testUsers,
|
|
5864
|
+
title?: string,
|
|
5865
|
+
}) => {
|
|
5866
|
+
const assignments: RoundRobinAssignmentInfo[] = []
|
|
5867
|
+
const selections: (string | undefined)[] = []
|
|
5868
|
+
|
|
5869
|
+
for (let i = 0; i < iterations; i++) {
|
|
5870
|
+
if (assignments.length !== i) {
|
|
5871
|
+
throw new Error("Invariant Violation: assignment not saved in history")
|
|
5872
|
+
}
|
|
5873
|
+
|
|
5874
|
+
const { selected } = weighted_round_robin({ assignments, users })
|
|
5875
|
+
selections.push(selected)
|
|
5876
|
+
|
|
5877
|
+
const assignment: RoundRobinAssignmentInfo = {
|
|
5878
|
+
id: i.toString(),
|
|
5879
|
+
userId: selected || '',
|
|
5880
|
+
key: 'test',
|
|
5881
|
+
timestamp: i, // simply ensures increasing timestamps per assignment
|
|
5882
|
+
}
|
|
5883
|
+
|
|
5884
|
+
// ensure that assignment order doesn't matter (e.g. weighted_round_robin sorts internally)
|
|
5885
|
+
if (i % 2 === 0) {
|
|
5886
|
+
assignments.push(assignment) // add to back
|
|
5887
|
+
} else {
|
|
5888
|
+
assignments.unshift(assignment) // add to front
|
|
5889
|
+
}
|
|
5890
|
+
}
|
|
5891
|
+
|
|
5892
|
+
assert(objects_equivalent(selections, expectedSelections), title + '\n' + JSON.stringify({ expected: expectedSelections, got: selections }, null, 2), title)
|
|
5893
|
+
}
|
|
5894
|
+
|
|
5895
|
+
run_assignment_simulation({ expectedSelections: [], iterations: 0 })
|
|
5896
|
+
run_assignment_simulation({ expectedSelections: [userIds[0]], iterations: 1 })
|
|
5897
|
+
run_assignment_simulation({ expectedSelections: [userIds[0], userIds[1]], iterations: 2 })
|
|
5898
|
+
run_assignment_simulation({ expectedSelections: [userIds[0], userIds[1], userIds[2]], iterations: 3 })
|
|
5899
|
+
run_assignment_simulation({ expectedSelections: [userIds[0], userIds[1], userIds[2], userIds[3]], iterations: 4 })
|
|
5900
|
+
run_assignment_simulation({ iterations: 5,
|
|
5901
|
+
expectedSelections: [
|
|
5902
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5903
|
+
userIds[0],
|
|
5904
|
+
],
|
|
5905
|
+
})
|
|
5906
|
+
run_assignment_simulation({ iterations: 6, expectedSelections: [
|
|
5907
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5908
|
+
userIds[0], userIds[2],
|
|
5909
|
+
]})
|
|
5910
|
+
run_assignment_simulation({ iterations: 7, expectedSelections: [
|
|
5911
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5912
|
+
userIds[0], userIds[2], userIds[3],
|
|
5913
|
+
]})
|
|
5914
|
+
run_assignment_simulation({ iterations: 8, expectedSelections: [
|
|
5915
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5916
|
+
userIds[0], userIds[2], userIds[3],
|
|
5917
|
+
userIds[0],
|
|
5918
|
+
]})
|
|
5919
|
+
run_assignment_simulation({ iterations: 9,
|
|
5920
|
+
expectedSelections: [
|
|
5921
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5922
|
+
userIds[0], userIds[2], userIds[3],
|
|
5923
|
+
userIds[0], userIds[3],
|
|
5924
|
+
],
|
|
5925
|
+
})
|
|
5926
|
+
run_assignment_simulation({ iterations: 10,
|
|
5927
|
+
expectedSelections: [
|
|
5928
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5929
|
+
userIds[0], userIds[2], userIds[3],
|
|
5930
|
+
userIds[0], userIds[3],
|
|
5931
|
+
userIds[0],
|
|
5932
|
+
],
|
|
5933
|
+
})
|
|
5934
|
+
run_assignment_simulation({ iterations: 11,
|
|
5935
|
+
expectedSelections: [
|
|
5936
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5937
|
+
userIds[0], userIds[2], userIds[3],
|
|
5938
|
+
userIds[0], userIds[3],
|
|
5939
|
+
userIds[0],
|
|
5940
|
+
userIds[0],
|
|
5941
|
+
],
|
|
5942
|
+
})
|
|
5943
|
+
run_assignment_simulation({ iterations: 12,
|
|
5944
|
+
expectedSelections: [
|
|
5945
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5946
|
+
userIds[0], userIds[2], userIds[3],
|
|
5947
|
+
userIds[0], userIds[3],
|
|
5948
|
+
userIds[0],
|
|
5949
|
+
userIds[0],
|
|
5950
|
+
userIds[0],
|
|
5951
|
+
],
|
|
5952
|
+
})
|
|
5953
|
+
run_assignment_simulation({ iterations: 13,
|
|
5954
|
+
expectedSelections: [
|
|
5955
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5956
|
+
userIds[0], userIds[2], userIds[3],
|
|
5957
|
+
userIds[0], userIds[3],
|
|
5958
|
+
userIds[0],
|
|
5959
|
+
userIds[0],
|
|
5960
|
+
userIds[0], userIds[1],
|
|
5961
|
+
],
|
|
5962
|
+
})
|
|
5963
|
+
run_assignment_simulation({ iterations: 14,
|
|
5964
|
+
expectedSelections: [
|
|
5965
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5966
|
+
userIds[0], userIds[2], userIds[3],
|
|
5967
|
+
userIds[0], userIds[3],
|
|
5968
|
+
userIds[0],
|
|
5969
|
+
userIds[0],
|
|
5970
|
+
userIds[0], userIds[1], userIds[2],
|
|
5971
|
+
],
|
|
5972
|
+
})
|
|
5973
|
+
run_assignment_simulation({ iterations: 15,
|
|
5974
|
+
expectedSelections: [
|
|
5975
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5976
|
+
userIds[0], userIds[2], userIds[3],
|
|
5977
|
+
userIds[0], userIds[3],
|
|
5978
|
+
userIds[0],
|
|
5979
|
+
userIds[0],
|
|
5980
|
+
userIds[0], userIds[1], userIds[2], userIds[3],
|
|
5981
|
+
],
|
|
5982
|
+
})
|
|
5983
|
+
}
|
|
5984
|
+
|
|
5818
5985
|
(async () => {
|
|
5819
5986
|
log_header("API")
|
|
5820
5987
|
|
|
@@ -5825,6 +5992,8 @@ const validate_schema = () => {
|
|
|
5825
5992
|
)
|
|
5826
5993
|
|
|
5827
5994
|
try {
|
|
5995
|
+
await test_weighted_round_robin()
|
|
5996
|
+
|
|
5828
5997
|
await validate_schema()
|
|
5829
5998
|
|
|
5830
5999
|
await Promise.all([
|
package/test_generated.pdf
CHANGED
|
Binary file
|