UNPKG

1.71 kBPlain TextView Raw
1/**
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License.
4 */
5import * as utils from './Utils'
6import { FilledEntityMap } from '@conversationlearner/models';
7
8describe('Util', () => {
9 describe('replace', () => {
10 test('Replace function should work', () => {
11
12 interface Otype {
13 name: string
14 id: string
15 }
16
17 let objects: Otype[] = [{ name: "o1", id: "1" }, { name: "o2", id: "2" }]
18 let newo: Otype = { name: "o2new", id: "2" }
19
20
21 // Act
22 const actual = utils.replace<Otype>(objects, newo, o => o.id)
23
24 // Assert
25 const replaced = actual.find(o => o.id === "2")
26 expect(replaced).toBe(newo)
27 })
28 })
29
30 describe('addEntitiesById', () => {
31 test('given filled entity map should return new filled entity map with entities able to be referenced by id', () => {
32 const filledEntityMap = new FilledEntityMap({
33 map: {
34 'entityName1': {
35 entityId: 'entityId',
36 values: [
37 {
38 userText: "userText",
39 displayText: "displayText",
40 builtinType: "builtinType",
41 resolution: {}
42 }
43 ]
44 }
45 }
46 })
47
48 const dualFilledEntityMap = utils.addEntitiesById(filledEntityMap)
49
50 expect(dualFilledEntityMap.ValueAsString('entityId')).toBe('displayText')
51 })
52 })
53})