Skip to content

Commit

Permalink
add cookie tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acvetkov committed Dec 31, 2015
1 parent 2cb2d94 commit 78f7650
Showing 1 changed file with 160 additions and 0 deletions.
160 changes: 160 additions & 0 deletions test/plugins/cookie/cookie.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import ChromeCookie from '../../../src/plugins/cookies/cookie';

describe.only('plugin/cookie', function () {

it('should create correct host-only cookie', function () {
const cookie = new ChromeCookie({url: 'http://my-domain.com'});
assert.deepEqual(cookie.toString(), {
name: '',
value: '',
domain: 'my-domain.com',
hostOnly: true,
httpOnly: false,
secure: false,
session: true,
path: '/'
});
});

it('should create correct all domains cookie', function () {
const cookie = new ChromeCookie({url: 'http://.my-domain.com'});
assert.deepEqual(cookie.toString(), {
name: '',
value: '',
domain: '.my-domain.com',
hostOnly: false,
httpOnly: false,
secure: false,
session: true,
path: '/'
});
});

it('should create correct all domains named cookie', function () {
const cookie = new ChromeCookie({url: 'http://.my-domain.com', name: 'cook'});
assert.deepEqual(cookie.toString(), {
name: 'cook',
value: '',
domain: '.my-domain.com',
hostOnly: false,
httpOnly: false,
secure: false,
session: true,
path: '/'
});
});

it('should create correct all domains named cookie with value', function () {
const cookie = new ChromeCookie({url: 'http://.my-domain.com', name: 'cook', value: 'val'});
assert.deepEqual(cookie.toString(), {
name: 'cook',
value: 'val',
domain: '.my-domain.com',
hostOnly: false,
httpOnly: false,
secure: false,
session: true,
path: '/'
});
});

it('should create correct all domains named cookie with value with custom path', function () {
const cookie = new ChromeCookie({
url: 'http://.my-domain.com',
name: 'cook',
value: 'val',
path: '/data'
});
assert.deepEqual(cookie.toString(), {
name: 'cook',
value: 'val',
domain: '.my-domain.com',
hostOnly: false,
httpOnly: false,
secure: false,
session: true,
path: '/data'
});
});

it('should create correct all domains named cookie with value with default domain path', function () {
const cookie = new ChromeCookie({
url: 'http://.my-domain.com/path/to',
name: 'cook',
value: 'val'
});
assert.deepEqual(cookie.toString(), {
name: 'cook',
value: 'val',
domain: '.my-domain.com',
hostOnly: false,
httpOnly: false,
secure: false,
session: true,
path: '/path/to'
});
});

it('should create correct all domains named secure cookie with value with default domain path', function () {
const cookie = new ChromeCookie({
url: 'http://.my-domain.com',
name: 'cook',
value: 'val',
secure: true
});
assert.deepEqual(cookie.toString(), {
name: 'cook',
value: 'val',
domain: '.my-domain.com',
hostOnly: false,
httpOnly: false,
secure: true,
session: true,
path: '/'
});
});

it('should create correct all domains httpOnly named cookie', function () {
const cookie = new ChromeCookie({
url: 'http://.my-domain.com',
name: 'cook',
httpOnly: true
});
assert.deepEqual(cookie.toString(), {
name: 'cook',
value: '',
domain: '.my-domain.com',
hostOnly: false,
httpOnly: true,
secure: false,
session: true,
path: '/'
});
});

it('should create correct all domains named cookie with expiration date', function () {
const cookie = new ChromeCookie({
url: 'http://.my-domain.com',
name: 'cook',
expirationDate: 1451579154.834
});
assert.deepEqual(cookie.toString(), {
name: 'cook',
value: '',
domain: '.my-domain.com',
hostOnly: false,
httpOnly: false,
secure: false,
session: false,
path: '/',
expirationDate: 1451579154.834
});
});

it('should throw exception if url is not passed', function () {
function call() {
return new ChromeCookie({name: 'data'});
}
assert.throws(call, 'details.url required', 'url is not passed');
});
});

0 comments on commit 78f7650

Please sign in to comment.