Skip to content

Commit

Permalink
testing cookie and csrf-header middlewres
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth committed Jul 17, 2020
1 parent 0b1dcb6 commit cb5ca04
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/middlewares/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
expect,
} from 'chai';
import 'mocha';
import { Request } from '../../src/request';
import { Result } from '../../src/result';

describe('middlewares/cookie', () => {
it('should be a class', () => {
Expand All @@ -14,4 +16,19 @@ describe('middlewares/cookie', () => {
it('should have a static method process', () => {
expect(Cookie.process,).to.be.a('function',);
},);
it('should not set cookies by default', () => {
expect(Cookie.prepare(<Request>{}),).to.deep.equal({cookies: {}},);
},);
it('should get cookies by default', () => {
expect(() => Cookie.process(<Result><unknown>{response: {cookies: {abc: 'def'}}}),).to.not.throw();
},);
it('should set cookies it has', () => {
expect(Cookie.prepare(<Request>{}),).to.deep.equal({cookies: {abc: 'def'}},);
},);
it('should change no cookies if there are none', () => {
expect(() => Cookie.process(<Result><unknown>{response: {cookies: {}}}),).to.not.throw();
},);
it('should set cookies it has', () => {
expect(Cookie.prepare(<Request>{}),).to.deep.equal({cookies: {abc: 'def'}},);
},);
},);
17 changes: 17 additions & 0 deletions test/middlewares/csrf-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
expect,
} from 'chai';
import 'mocha';
import { Request } from '../../src/request';
import { Result } from '../../src/result';

describe('middlewares/csrf-header', () => {
it('should be a class', () => {
Expand All @@ -14,4 +16,19 @@ describe('middlewares/csrf-header', () => {
it('should have a static method process', () => {
expect(CsrfHeader.process,).to.be.a('function',);
},);
it('should not set token by default', () => {
expect(CsrfHeader.prepare(<Request>{}),).to.deep.equal({headers: {}},);
},);
it('should get token by default', () => {
expect(() => CsrfHeader.process(<Result><unknown>{response: {headers: {'x-csrf-token': 'def'}}}),).to.not.throw();
},);
it('should set token it has', () => {
expect(CsrfHeader.prepare(<Request>{}),).to.deep.equal({headers: {'x-csrf-token': 'def'}},);
},);
it('should change no token if there\'s none', () => {
expect(() => CsrfHeader.process(<Result><unknown>{response: {headers: {}}}),).to.not.throw();
},);
it('should set token it has', () => {
expect(CsrfHeader.prepare(<Request>{}),).to.deep.equal({headers: {'x-csrf-token': 'def'}},);
},);
},);

0 comments on commit cb5ca04

Please sign in to comment.