Migrate experiments and helpfulness to Hydro (#16059)
* Migrate experiments and helpfulness to Hydro * Clean out old tests * ...and more old tests to delete
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
const request = require('supertest')
|
||||
const Airtable = require('airtable')
|
||||
const nock = require('nock')
|
||||
const app = require('../../server')
|
||||
|
||||
jest.mock('airtable')
|
||||
Airtable.mockImplementation(function () {
|
||||
this.base = () => () => ({
|
||||
create: () => [{ getId: () => 'TESTID' }],
|
||||
update: () => true
|
||||
})
|
||||
})
|
||||
|
||||
describe('POST /events', () => {
|
||||
jest.setTimeout(60 * 1000)
|
||||
|
||||
@@ -47,91 +38,6 @@ describe('POST /events', () => {
|
||||
.expect(code)
|
||||
}
|
||||
|
||||
describe('HELPFULNESS', () => {
|
||||
const example = {
|
||||
type: 'HELPFULNESS',
|
||||
url: 'https://example.com',
|
||||
vote: 'Yes',
|
||||
email: 'test@example.com',
|
||||
comment: 'This is the best page ever',
|
||||
category: 'Other'
|
||||
}
|
||||
|
||||
it('should accept a valid object', () =>
|
||||
checkEvent(example, 201)
|
||||
)
|
||||
|
||||
it('should reject extra properties', () =>
|
||||
checkEvent({ ...example, toothpaste: false }, 400)
|
||||
)
|
||||
|
||||
it('should not accept if type is missing', () =>
|
||||
checkEvent({ ...example, type: undefined }, 400)
|
||||
)
|
||||
|
||||
it('should not accept if url is missing', () =>
|
||||
checkEvent({ ...example, url: undefined }, 400)
|
||||
)
|
||||
|
||||
it('should not accept if url is misformatted', () =>
|
||||
checkEvent({ ...example, url: 'examplecom' }, 400)
|
||||
)
|
||||
|
||||
it('should not accept if vote is missing', () =>
|
||||
checkEvent({ ...example, vote: undefined }, 400)
|
||||
)
|
||||
|
||||
it('should not accept if vote is not boolean', () =>
|
||||
checkEvent({ ...example, vote: 'true' }, 400)
|
||||
)
|
||||
|
||||
it('should not accept if email is misformatted', () =>
|
||||
checkEvent({ ...example, email: 'testexample.com' }, 400)
|
||||
)
|
||||
|
||||
it('should not accept if comment is not string', () =>
|
||||
checkEvent({ ...example, comment: [] }, 400)
|
||||
)
|
||||
|
||||
it('should not accept if category is not an option', () =>
|
||||
checkEvent({ ...example, category: 'Fabulous' }, 400)
|
||||
)
|
||||
})
|
||||
|
||||
describe('EXPERIMENT', () => {
|
||||
const example = {
|
||||
type: 'EXPERIMENT',
|
||||
user: 'ef17cf45-ba3c-4de0-9140-84eb85f0797d',
|
||||
test: 'my-example-test',
|
||||
group: 'control',
|
||||
success: 'yes'
|
||||
}
|
||||
|
||||
it('should accept a valid object', () =>
|
||||
checkEvent(example, 201)
|
||||
)
|
||||
|
||||
it('should reject extra fields', () =>
|
||||
checkEvent({ ...example, toothpaste: false }, 400)
|
||||
)
|
||||
|
||||
it('should require a long unique user-id', () =>
|
||||
checkEvent({ ...example, 'user-id': 'short' }, 400)
|
||||
)
|
||||
|
||||
it('should require a test', () =>
|
||||
checkEvent({ ...example, test: undefined }, 400)
|
||||
)
|
||||
|
||||
it('should require a valid group', () =>
|
||||
checkEvent({ ...example, group: 'revolution' }, 400)
|
||||
)
|
||||
|
||||
it('should default the success field', () =>
|
||||
checkEvent({ ...example, success: undefined }, 201)
|
||||
)
|
||||
})
|
||||
|
||||
const baseExample = {
|
||||
context: {
|
||||
// Primitives
|
||||
@@ -506,42 +412,3 @@ describe('POST /events', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('PUT /events/:id', () => {
|
||||
jest.setTimeout(60 * 1000)
|
||||
|
||||
let csrfToken = ''
|
||||
let agent
|
||||
|
||||
beforeEach(async () => {
|
||||
process.env.AIRTABLE_API_KEY = '$AIRTABLE_API_KEY$'
|
||||
process.env.AIRTABLE_BASE_KEY = '$AIRTABLE_BASE_KEY$'
|
||||
agent = request.agent(app)
|
||||
const csrfRes = await agent.get('/csrf')
|
||||
csrfToken = csrfRes.body.token
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env.AIRTABLE_API_KEY
|
||||
delete process.env.AIRTABLE_BASE_KEY
|
||||
csrfToken = ''
|
||||
})
|
||||
|
||||
const example = {
|
||||
type: 'HELPFULNESS',
|
||||
url: 'https://example.com',
|
||||
vote: 'Yes',
|
||||
email: 'test@example.com',
|
||||
comment: 'This is the best page ever',
|
||||
category: 'Other'
|
||||
}
|
||||
|
||||
it('should update an existing HELPFULNESS event', () =>
|
||||
agent
|
||||
.put('/events/TESTID')
|
||||
.send(example)
|
||||
.set('Accept', 'application/json')
|
||||
.set('csrf-token', csrfToken)
|
||||
.expect(200)
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user