Files
datasheet-server/test/serverProcess.js
Lachlan Kermode a9eb6ea6e2 Release v0.5.0 (#61)
* remove explicit ID from events in timemap setup

* Fixed internal anchor link headline

* update fmt

* Bump lodash from 4.17.15 to 4.17.19

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>

* Wrote validation functions and getter to grab appropriate validation function

* Collapsed filters and narratives into associations; modified default tabs to reflect

* Refactoring events to have only associations; created associations tab and related export tab

* Clean up with event related associations

* Delete validation for now; not relevant to this PR

* Bump node-fetch from 2.6.0 to 2.6.1

Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1)

Signed-off-by: dependabot[bot] <support@github.com>

* Removed gsheets tab in config, unused import in package json

* try/catch to prioritise local.config.js

* Removing export categories endpoint

* Removed categories from list and using test_export_events

* Test associations

* Removed comment regarding categories endpoint

* Removing unnecessary test_export_events endpoint

* Linting threw error stating that we use path module to join instead of +

* generalise LocalFetcher to support many sheet types (xlsx, ods, etc)

* rm getFileExt

* use tab as delimiter in intermediate representation

* Bump googleapis from 32.0.0 to 39.1.0

Bumps [googleapis](https://github.com/googleapis/google-api-nodejs-client) from 32.0.0 to 39.1.0.
- [Release notes](https://github.com/googleapis/google-api-nodejs-client/releases)
- [Changelog](https://github.com/googleapis/google-api-nodejs-client/blob/master/CHANGELOG.md)
- [Commits](https://github.com/googleapis/google-api-nodejs-client/compare/v32.0.0...v39.1.0)

Signed-off-by: dependabot[bot] <support@github.com>

* Fixed tests

* fix example sheet

Co-authored-by: Christoph Knoth <github@christoph-knoth.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: efarooqui <efarooqui@pandora.com>
Co-authored-by: Ebrahem Farooqui <ebefarooqui@gmail.com>
Co-authored-by: Lachlan <Kermode>
2020-11-25 13:50:55 +00:00

91 lines
1.8 KiB
JavaScript

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('SETUP: launching server and updating...')
serverProc = childProcess.spawn('yarn', ['dev'], {
cwd: '.',
stdio: 'ignore'
})
serverProc.on('exit', function (code, signal) {
serverExited = true
})
function pingUpdate () {
const expected = {
success: 'All sheets updated'
}
return fetch(`${SERVER_ROOT}/api/update`)
.then(checkStatus)
.then(res => res.json())
.then(json => {
t.deepEqual(json, expected)
t.end()
})
}
setTimeout(pingUpdate, 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)
})
const passUrls = [
'/api/',
]
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 => {
console.info('JSON: ', 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()
}
})
})
})