diff --git a/core/server/server.spec.js b/core/server/server.spec.js index 95da4cee5a4d1bf37af4998f94552f6766ca5e31..1b1e8d9bac7a8e89ff594969034b2787c30bad33 100644 --- a/core/server/server.spec.js +++ b/core/server/server.spec.js @@ -9,6 +9,7 @@ const isSvg = require('is-svg') const path = require('path') const sinon = require('sinon') const portfinder = require('portfinder') +const Joi = require('joi') const svg2img = require('../../gh-badges/lib/svg-to-img') const { createTestServer } = require('./in-process-server-test-helpers') @@ -128,24 +129,30 @@ describe('The server', function() { describe('analytics endpoint', function() { it('should return analytics in the expected format', async function() { + const countSchema = Joi.array() + .items( + Joi.number() + .integer() + .min(0) + .required() + ) + .length(36) + .required() + const analyticsSchema = Joi.object({ + vendorMonthly: countSchema, + rawMonthly: countSchema, + vendorFlatMonthly: countSchema, + rawFlatMonthly: countSchema, + vendorFlatSquareMonthly: countSchema, + rawFlatSquareMonthly: countSchema, + }).required() + const res = await fetch(`${baseUrl}$analytics/v1`) expect(res.ok).to.be.true + const json = await res.json() - const expectedKeys = [ - 'vendorMonthly', - 'rawMonthly', - 'vendorFlatMonthly', - 'rawFlatMonthly', - 'vendorFlatSquareMonthly', - 'rawFlatSquareMonthly', - ] - expect(json).to.have.all.keys(...expectedKeys) - - Object.values(json).forEach(stats => { - expect(stats) - .to.be.an('array') - .with.length(36) - }) + + Joi.assert(json, analyticsSchema) }) }) })