Ghost/test/api-acceptance/content/key_authentication_spec.js
Daniel Lockyer 04fb7f8e69
Refactored acceptance tests to use async-await
- refactoring the acceptance tests to use async-await removes all the Promise
  chaining we had, and streamlines the coding styles we have across the code so
  test files are more alike
2020-12-03 08:47:01 +00:00

32 lines
1.0 KiB
JavaScript

const should = require('should');
const supertest = require('supertest');
const testUtils = require('../../utils');
const localUtils = require('./utils');
const config = require('../../../core/shared/config');
describe('Content API key authentication', function () {
let request;
before(async function () {
await testUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('api_keys');
});
it('Can not access without key', async function () {
await request.get(localUtils.API.getApiQuery('posts/'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(403);
});
it('Can access with with valid key', async function () {
const key = localUtils.getValidKey();
await request.get(localUtils.API.getApiQuery(`posts/?key=${key}`))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200);
});
});