-
Notifications
You must be signed in to change notification settings - Fork 11
/
testgpt.config.yaml
165 lines (137 loc) · 5.49 KB
/
testgpt.config.yaml
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
.ts:
techs:
- jest
instructions:
- use 2 spaces for indentation
- wrap each group of tests in a describe block
- Don't forget to import the things you need.
examples:
- fileName: array_utils.test.ts
code: |
export const addItem = (array: any[], item: any) => {
return [...array, item];
};
export const removeItem = (array: any[], item: any) => {
return array.filter((i) => i !== item);
};
export const toggleItem = (array: any[], item: any) => {
return array.includes(item) ? removeItem(array, item) : addItem(array, item);
};
export const toggleItemInArray = (array: any[], item: any) => {
return array.includes(item) ? removeItem(array, item) : addItem(array, item);
};
tests: |
import {
addItem,
removeItem,
toggleItem,
toggleItemInArray,
} from "./array_utils";
describe("array_utils", () => {
it("should add item to the array", () => {
const array = ["item1", "item2"];
const itemToAdd = "item3";
expect(addItem(array, itemToAdd)).toEqual([...array, itemToAdd]);
});
describe("removeItem", () => {
it("should remove item from the array", () => {
const array = ["item1", "item2", "item3"];
const itemToRemove = "item2";
expect(removeItem(array, itemToRemove)).toEqual(["item1", "item3"]);
});
});
describe("toggleItem", () => {
it("should remove the item if it already exists in the array", () => {
const array = ["item1", "item2"];
const itemToToggle = "item2";
expect(toggleItem(array, itemToToggle)).toEqual(["item1"]);
});
it("should add the item if it doesn't exist in the array", () => {
const array = ["item1", "item2"];
const itemToToggle = "item3";
expect(toggleItem(array, itemToToggle)).toEqual([...array, itemToToggle]);
});
});
describe("toggleItemInArray", () => {
it("should remove the item if it already exists in the array", () => {
const array = ["item1", "item2"];
const itemToToggle = "item2";
expect(toggleItemInArray(array, itemToToggle)).toEqual(["item1"]);
});
it("should add the item if it doesn't exist in the array", () => {
const array = ["item1", "item2"];
const itemToToggle = "item3";
expect(toggleItemInArray(array, itemToToggle)).toEqual([
...array,
itemToToggle,
]);
});
});
});
- fileName: data.ts
code: |
import axios from "axios";
import chalk from "chalk";
export const fetchDogNames = async () => {
console.log(chalk.blue("Fetching dog names..."));
const response = await fetch("https://dog.ceo/api/breeds/list/all");
const data = await response.json();
return Object.keys(data.message);
};
export const fetchCatNames = async () => {
console.log(chalk.blue("Fetching cat names..."));
const response = await axios.get("https://api.thecatapi.com/v1/breeds");
return response.data.map((cat: any) => cat.name);
};
export const fetchDogImage = async (breed: string) => {
console.log(chalk.green(`Fetching ${breed} image...`));
const response = await fetch(
`https://dog.ceo/api/breed/${breed}/images/random`
);
const data = await response.json();
return data.message;
};
tests: |
import axios from "axios";
import { fetchDogImage, fetchCatNames, fetchDogNames } from "./data";
jest.mock("chalk", () => ({
blue: jest.fn((text) => text),
green: jest.fn((text) => text),
}));
(global as any).fetch = jest.fn();
jest.mock("axios", () => ({
get: jest.fn(),
}));
describe("data", () => {
it("should fetch dog names", async () => {
(global as any).fetch.mockImplementationOnce(() =>
Promise.resolve({
json: () => Promise.resolve({ message: { bulldog: [], poodle: [] } }),
})
);
const dogNames = await fetchDogNames();
expect(dogNames).toEqual(["bulldog", "poodle"]);
});
it("should fetch cat names", async () => {
(axios.get as jest.Mock).mockImplementationOnce(() =>
Promise.resolve({
data: [{ name: "catie" }, { name: "kitty" }],
})
);
const catNames = await fetchCatNames();
expect(catNames).toEqual(["catie", "kitty"]);
});
it("should fetch dog image", async () => {
const link = "https://dog.ceo/api/breed/bulldog/images/random";
(global as any).fetch.mockImplementationOnce(() =>
Promise.resolve({
json: () =>
Promise.resolve({
message: link,
}),
})
);
const dogImage = await fetchDogImage("bulldog");
expect(dogImage).toEqual(link);
});
});