File tree Expand file tree Collapse file tree 4 files changed +103
-3
lines changed
Expand file tree Collapse file tree 4 files changed +103
-3
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ import React from 'react';
22import { render , screen } from '@testing-library/react' ;
33import App from './App' ;
44
5- test ( 'renders learn react link ' , ( ) => {
5+ test ( 'renders react logo text ' , ( ) => {
66 render ( < App /> ) ;
7- const linkElement = screen . getByText ( / l e a r n r e a c t / i) ;
8- expect ( linkElement ) . toBeInTheDocument ( ) ;
7+ const logoTextElement = screen . getByText ( / N o t e s / i) ;
8+ expect ( logoTextElement ) . toBeInTheDocument ( ) ;
99} ) ;
Original file line number Diff line number Diff line change 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+ } )
Original file line number Diff line number Diff line change 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+ } )
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments