Покрытие тестами апи для создания опроса
This commit is contained in:
parent
c7e5fcebe2
commit
223ec77178
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,6 +17,7 @@
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.idea
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
|
||||
5
jest.config.js
Normal file
5
jest.config.js
Normal file
@ -0,0 +1,5 @@
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
};
|
||||
9130
package-lock.json
generated
9130
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@babel/preset-typescript": "^7.17.12",
|
||||
"@chakra-ui/icons": "^2.0.0",
|
||||
"@chakra-ui/react": "^2.1.0",
|
||||
"@emotion/react": "^11.9.0",
|
||||
@ -25,13 +26,15 @@
|
||||
"react-router-dom": "^6.3.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"react-time-picker": "^4.5.0",
|
||||
"ts-jest": "^28.0.3",
|
||||
"typescript": "^4.6.4",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"test": "jest",
|
||||
"init-test": "ts-jest config:init",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
|
||||
11
src/API/quiz.ts
Normal file
11
src/API/quiz.ts
Normal file
@ -0,0 +1,11 @@
|
||||
const axios = require('axios');
|
||||
|
||||
export const create = axios.create({
|
||||
baseURL: "http://localhost:1488/quiz/create",
|
||||
// baseURL: process.env.URL + "/quiz/create",
|
||||
timeout: 1000,
|
||||
method: "post",
|
||||
validateStatus: function (status: number) {
|
||||
return status === 201;
|
||||
},
|
||||
});
|
||||
@ -10,6 +10,12 @@ const statusValues: any = ['draft', 'template', 'stop', 'start']
|
||||
|
||||
export default () => {
|
||||
|
||||
const Options = React.useMemo(() => () => (
|
||||
statusValues.map((e:string,i:number)=> {
|
||||
return <option key={i} value={e}>{e}</option>
|
||||
})
|
||||
), []);
|
||||
|
||||
return(
|
||||
<Box
|
||||
padding="20px"
|
||||
@ -50,9 +56,7 @@ export default () => {
|
||||
<Text>Статус опроса</Text>
|
||||
<Field as={Select} name="status">
|
||||
{
|
||||
statusValues.map((e:string,i:number)=> {
|
||||
return <option key={i} value={e}>{e}</option>
|
||||
})
|
||||
<Options/>
|
||||
}
|
||||
</Field>
|
||||
</Stack>
|
||||
@ -77,7 +81,7 @@ export default () => {
|
||||
backgroundColor="lightgray"
|
||||
padding="20px"
|
||||
>
|
||||
<Text>Выбрать время до которого проводится опрос</Text>
|
||||
<Text>Время прохождения опроса</Text>
|
||||
<Field
|
||||
as={TimePicker}
|
||||
name="time"
|
||||
@ -103,7 +107,6 @@ export default () => {
|
||||
selected={values.date}
|
||||
dateFormat="MM/dd/yyyy"
|
||||
onChange={(e:any) => {
|
||||
console.log(e)
|
||||
setFieldValue("date", e)
|
||||
}}
|
||||
minDate={new Date()}
|
||||
|
||||
1
src/tests/.env.development
Normal file
1
src/tests/.env.development
Normal file
@ -0,0 +1 @@
|
||||
URL = "localhost:1488"
|
||||
26
src/tests/api.test.ts
Normal file
26
src/tests/api.test.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import {create} from '../API/quiz'
|
||||
const inputBody = {
|
||||
"fingerprinting": true,
|
||||
"repeatable": true,
|
||||
"note_prevented": true,
|
||||
"mail_notifications": true,
|
||||
"unique_answers": true,
|
||||
"name": "string",
|
||||
"description": "string",
|
||||
"config": "",
|
||||
"status": "draft",
|
||||
"limit": 0,
|
||||
"pausable": true,
|
||||
"question_cnt": 0
|
||||
};
|
||||
it('Запросы положительный', () => {
|
||||
expect.assertions(1);
|
||||
return create.request({body: inputBody})
|
||||
.then((e: any) => {
|
||||
expect(e.status).toBe(201);
|
||||
})
|
||||
.catch((e: any) => {
|
||||
expect(e.status).not.toBe(4);
|
||||
})
|
||||
console.log("aaa")
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user