This commit is contained in:
Lachlan Kermode
2018-12-14 18:23:48 +00:00
parent 18ddc6c48b
commit 1f2a2953b1
3 changed files with 99 additions and 103 deletions

View File

@@ -1,8 +1,6 @@
import test from 'ava'
import R from 'ramda'
import {
defaultBlueprint,
defaultResource,
defaultBlueprint
} from '../src/lib/blueprinters'
import rows from '../src/blueprinters/rows'
@@ -29,7 +27,7 @@ test('defaultBlueprint exports', t => {
test('rows blueprinter', t => {
const expected = [
{ h1: 1, h2: 2, h3: 3 },
{ h1: 4, h2: 5, h3: 6 },
{ h1: 4, h2: 5, h3: 6 }
]
const actual = rows(egInput1)
t.deepEqual(expected, actual)
@@ -37,8 +35,8 @@ test('rows blueprinter', t => {
test('deeprows blueprinter', t => {
const expected = [
{ 'hs': [1,2,3] },
{ 'hs': [4,5,6] }
{ 'hs': [1, 2, 3] },
{ 'hs': [4, 5, 6] }
]
const actual = deeprows(egInput1)
t.deepEqual(expected, actual)

95
test/serverProcess.js Normal file
View File

@@ -0,0 +1,95 @@
import test from 'ava'
import fetch from 'node-fetch'
import childProcess from 'child_process'
const SERVER_LAUNCH_WAIT_TIME = 10 * 1000
const SERVER_ROOT = 'http://localhost:4040'
let serverProc = null
let serverExited = false
function checkStatus (res) {
if (res.ok) {
return res
} else {
throw new Error('Route is not present')
}
}
/* SETUP: launch a development server with a wait time */
test.before.cb(t => {
console.log('launching server...')
serverProc = childProcess.spawn('yarn', ['dev'], {
cwd: '.',
stdio: 'ignore'
})
serverProc.on('exit', function (code, signal) {
serverExited = true
})
setTimeout(t.end, SERVER_LAUNCH_WAIT_TIME)
})
/* CLEANUP: kill the server */
test.after(function () {
console.log('killing server...')
serverProc.kill('SIGKILL')
})
test('should launch', t => {
t.false(serverExited)
})
test('should update', t => {
const expected = {
success: 'All sheets updated'
}
return fetch(`${SERVER_ROOT}/api/update`)
.then(checkStatus)
.then(res => res.json())
.then(json => {
t.deepEqual(json, expected)
})
})
const passUrls = [
// /
'/api/',
// /blueprints
'/api/blueprints',
// /:sheet/:tab/:resource
'/api/example/export_events/rows',
// /:sheet/:tab/:resource/:frag
'/api/example/export_events/rows/1'
]
const failUrls = [
// /:sheet
'/api/example',
// /:sheet/:tab
'/api/example/events'
]
passUrls.forEach(function (url) {
test(`should respond successfully to request for ${url}`, t => {
return fetch(`${SERVER_ROOT}${url}`)
.then(checkStatus)
.then(res => res.json())
.then(json => {
t.pass()
})
})
})
failUrls.forEach(function (url) {
test(`should respond with 404 for ${url}`, t => {
return fetch(`${SERVER_ROOT}${url}`)
.then(res => {
if (!res.ok) {
t.pass()
} else {
t.fail()
}
})
})
})

View File

@@ -1,97 +0,0 @@
import test from 'ava'
import fetch from 'node-fetch'
import child_process from 'child_process'
const SERVER_LAUNCH_WAIT_TIME = 10 * 1000
const SERVER_ROOT = 'http://localhost:4040'
let server_proc = null
let server_exited = false
function checkStatus(res) {
if (res.ok) {
return res
} else {
throw new Error('Route is not present')
}
}
/* SETUP: launch a development server with a wait time */
test.before.cb(t => {
console.log("launching server...")
server_proc = child_process.spawn('yarn', ['dev'], {
cwd: '.',
stdio: 'ignore'
})
server_proc.on('exit', function(code, signal) {
server_exited = true
})
setTimeout(t.end, SERVER_LAUNCH_WAIT_TIME)
})
/* CLEANUP: kill the server */
test.after(function() {
console.log("killing server...")
server_proc.kill('SIGKILL')
})
test('should launch', t => {
t.false(server_exited)
})
test('should update', t => {
const expected = {
success: "All sheets updated"
}
return fetch(`${SERVER_ROOT}/api/update`)
.then(checkStatus)
.then(res => res.json())
.then(json => {
t.deepEqual(json, expected)
})
})
const passUrls = [
// /
'/api/',
// /blueprints
'/api/blueprints',
// /:sheet/:tab/:resource
'/api/example/export_events/rows',
// /:sheet/:tab/:resource/:frag
'/api/example/export_events/rows/1'
]
const failUrls = [
// /:sheet
'/api/example',
// /:sheet/:tab
'/api/example/events'
]
passUrls.forEach(function(url) {
test(`should respond successfully to request for ${url}`, t => {
return fetch(`${SERVER_ROOT}${url}`)
.then(checkStatus)
.then(res => res.json())
.then(json => {
t.pass()
})
})
})
failUrls.forEach(function(url) {
test(`should respond with 404 for ${url}`, t => {
return fetch(`${SERVER_ROOT}${url}`)
.then(res => {
if (!res.ok) {
t.pass()
} else {
t.fail()
}
})
})
})