Chai assertions for testing Akamai configurations.
- Akamai Staging Network assertion
- Akamai configuration variable assertion
- Akamai Cookie Token assertion
- full
Set-Cookie
assertion
Install via npm.
npm install lukaszczerpak/chai-akamai
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;
});
});
});
The Chai Akamai module provides a number of assertions
for the expect
and should
interfaces.
Assert that a Response
object comes from Akamai Staging Network.
expect(res).to.be.akamaiStaging
- @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');
- @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/);
- @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);
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.
chai-akamai is licensed under the MIT license.