Skip to content

Akamai specific assertions for the Chai Assertion Library.

Notifications You must be signed in to change notification settings

lukaszczerpak/chai-akamai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chai Akamai

Chai assertions for testing Akamai configurations.

Features

  • Akamai Staging Network assertion
  • Akamai configuration variable assertion
  • Akamai Cookie Token assertion
  • full Set-Cookie assertion

Installation

Install via npm.

npm install lukaszczerpak/chai-akamai

Plugin

Use this plugin as you would all other Chai plugins.

const chai = require('chai');

chai.use(require('chai-akamai'));

With supertest-akamai gives powerful framework to build unit test suites:

const chai = require('chai');
const expect = chai.expect;
const akamaiReq = require('supertest-akamai');

chai.use(require('chai-http'));
chai.use(require('chai-akamai'));

const request = akamaiReq('http://www.example.com', 'example.com.edgesuite-staging.net').get('/about-us');

describe('sanity check', function () {
  it('respond with OK', function () {
    return paywallReq
      .expect((res) => {
        expect(res.statusCode).to.equal(200);
        expect(res).to.be.akamaiStaging;
      });
  });
});

Assertions

The Chai Akamai module provides a number of assertions for the expect and should interfaces.

.akamaiStaging

Assert that a Response object comes from Akamai Staging Network.

expect(res).to.be.akamaiStaging

.akamaiVariable (key[, value])

  • @param {String} Configuration Variable key
  • @param {String|RegExp} Configuration Variable value (optional)

Assert that a Response object has a Configuration Variable. If a value is provided, equality to value will be asserted. You may also pass a regular expression to check.

expect(res).to.have.akamaiVariable('PMUSER_MYVAR1', 'abc');

.cookie

  • @param {String} parameter name
  • @param {String|RegExp} parameter value

Assert that a Request or Response object has a cookie header with a given key, (optionally) equal to value. You may also pass a regular expression to check.

expect(req).to.have.cookie('session_id');
expect(req).to.have.cookie('session_id', '1234');
expect(req).to.not.have.cookie('PHPSESSID');
expect(res).to.have.cookie('session_id');
expect(res).to.have.cookie('session_id', '1234');
expect(res).to.not.have.cookie('PHPSESSID');
expect(req).to.have.cookie('mycookie1', /^text/);

.akamaiCookieToken

  • @param {String} cookie name

Assert that a Response object has a cookie token with given name.

expect(res).to.have.akamaiCookieToken('paywall').to.have.property('data').to.be.equal('userid=1234');
expect(res).to.have.akamaiCookieToken('paywall').to.have.property('exp').to.be.closeTo(new Date(), 60);

.akamaiRedirectTo

Assert that a Response object comes from Akamai Server and it is a redirection to the given URL:

expect(res).to.be.akamaiRedirectTo(301, 'http://www.example.com/')

This can be useful for testing Edge Redirector policies or redirects defined in site delivery configuration.

License

chai-akamai is licensed under the MIT license.

About

Akamai specific assertions for the Chai Assertion Library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published