-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchKeyValuePair.test.js
74 lines (54 loc) · 2.27 KB
/
searchKeyValuePair.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const getCharacters = require('./searchKeyValuePair');
const {act} = require("react-dom/test-utils");
describe("getCharacters function", () => {
test("it should return an empty array when the key is not available", () => {
const characters = {"characters": [
{"name": "Bill Cipher", "age":"Unknown", "speciality":"warp reality"}]
};
const key = "city";
const value = "Porto";
const actualResult = getCharacters(characters, key, value);
const expectedResult = [];
expect(actualResult).toEqual(expectedResult);
})
test("it should return an empty array when the value is not matching", () => {
const characters = {"characters": [
{"name": "Bill Cipher", "age":"Unknown", "speciality":"warp reality"}]
};
const key = "name";
const value = "Patricia";
const actualResult = getCharacters(characters, key, value);
const expectedResult = [];
expect(actualResult).toEqual(expectedResult);
})
test("it should return all information from Bill Cipher", () => {
const characters = {"characters": [
{"name": "Bill Cipher", "age":"Unknown", "speciality":"warp reality"}]
};
const key = "name";
const value = "Bill Cipher";
const actualResult = getCharacters(characters, key, value);
const expectedResult = [{"name":"Bill Cipher", "age":"Unknown", "speciality":"warp reality"}];
expect(actualResult).toEqual(expectedResult);
})
test("it should return all information from Bill Cipher when there is no 100% of name matching", () => {
const characters = {"characters": [
{"name": "Bill Cipher", "age":"Unknown", "speciality":"warp reality"}]
};
const key = "name";
const value = "Bill";
const actualResult = getCharacters(characters, key, value);
const expectedResult = [{"name":"Bill Cipher", "age":"Unknown", "speciality":"warp reality"}];
expect(actualResult).toEqual(expectedResult);
});
test("it should be case sensitive when the it's doing the matching", () => {
const characters = {"characters": [
{"name": "Bill Cipher", "age":"Unknown", "speciality":"warp reality"}]
};
const key = "name";
const value = "bill";
const actualResult = getCharacters(characters, key, value);
const expectedResult = [{"name":"Bill Cipher", "age":"Unknown", "speciality":"warp reality"}];
expect(actualResult).toEqual(expectedResult);
})
})