Skip to content

Commit e3dbf0d

Browse files
committed
make some tests
1 parent ccae40e commit e3dbf0d

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed

client/src/App.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import App from './App';
44

5-
test('renders learn react link', () => {
5+
test('renders react logo text', () => {
66
render(<App />);
7-
const linkElement = screen.getByText(/learn react/i);
8-
expect(linkElement).toBeInTheDocument();
7+
const logoTextElement = screen.getByText(/Notes/i);
8+
expect(logoTextElement).toBeInTheDocument();
99
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const authMiddleware = require("./auth.middleware");
2+
3+
test('block on incorrect token', done => {
4+
const req = {
5+
headers: {
6+
authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJraXJpZXNoa2kifQ.1rvQo1jjvB-mgTmxSGp7qWDvLGxpxY2ZHMe6qZfxOok'
7+
},
8+
url: "/example"
9+
}
10+
11+
const res = {
12+
status(code) {
13+
try {
14+
expect(code).toBe(401)
15+
return this
16+
} catch (error) {
17+
done(error)
18+
}
19+
},
20+
json(obj) {
21+
try {
22+
expect(obj).toEqual({ message: 'Нет авторизации' })
23+
done()
24+
} catch (error) {
25+
done(error)
26+
}
27+
}
28+
}
29+
30+
const next = () => {
31+
throw new Error('next')
32+
done()
33+
}
34+
35+
expect(() => authMiddleware(req, res, next)).not.toThrow('next')
36+
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const httpsMiddleware = require("./https.middleware");
2+
3+
test('correct redirect', done => {
4+
const req = {
5+
header: query => {
6+
switch (query) {
7+
case 'x-forwarded-proto':
8+
return 'http'
9+
case 'host':
10+
return 'test.host'
11+
default:
12+
break
13+
}
14+
},
15+
url: "/example"
16+
}
17+
18+
const res = {
19+
redirect(address) {
20+
try {
21+
expect(address).toBe(`https://test.host/example`)
22+
done()
23+
} catch (error) {
24+
done(error)
25+
}
26+
}
27+
}
28+
29+
const next = done
30+
31+
httpsMiddleware(req, res, next)
32+
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { checkNote } = require('./NoteCheck')
2+
3+
const noteTemplate = {
4+
id: "qweRty123",
5+
name: "note",
6+
color: "GREEN",
7+
text: "lorem ipsum adamet amer",
8+
order: 754444444424552
9+
}
10+
11+
test('check correct validation', () => {
12+
let note = noteTemplate
13+
expect(checkNote(note)).toBe(true)
14+
})
15+
16+
test('check validation with correct missing of "order"', () => {
17+
let note = noteTemplate
18+
delete note.order
19+
expect(checkNote(note)).toBe(true)
20+
})
21+
22+
test('check validation with incorrect missing', () => {
23+
let note = noteTemplate
24+
delete note.id
25+
expect(checkNote(note)).toBe(false)
26+
})
27+
28+
test('check incorrect validation', () => {
29+
let note = noteTemplate
30+
note.id = null
31+
expect(checkNote(note)).toBe(false)
32+
})

0 commit comments

Comments
 (0)