Rewrite test of analytics endpoint (#2810)

This test is being weirdly flaky in #2809. The problem seems to be in the test helper code, so I rewrote this using Joi.

I imagine the change has to do with a change to the test ordering. It's a bit puzzling.

However, the new test seems fine (and the endpoint is rarely used; not critical to begin with).
This commit is contained in:
Paul Melnikow
2019-01-18 23:51:07 -05:00
committed by GitHub
parent 69ced81cd1
commit 94acb92258

View File

@@ -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)
})
const json = await res.json()
Joi.assert(json, analyticsSchema)
})
})
})