ci: so it Begins!

This commit is contained in:
Begin
2020-10-26 14:30:23 +00:00
parent c836a34749
commit e03010bdaf
23 changed files with 4846 additions and 2 deletions

View File

@@ -0,0 +1,58 @@
let test = require('tape')
let tiny = require('tiny-json-http')
let sandbox = require('@architect/sandbox')
let url = 'http://localhost:6666'
/**
* Sandbox / http test
* - Demonstrates execising basic web integration tests using the local dev server
*/
test('Set up env', t => {
t.plan(1)
t.ok(sandbox, 'sandbox loaded')
})
test('Start sandbox', async t => {
t.plan(1)
let result = await sandbox.start()
t.ok(result, 'Sandbox started!')
})
test('get / (continuation-passing style)', t => {
t.plan(1)
tiny.get({url},
function win (err, result) {
if (err) {
t.fail(err)
} else {
t.ok(result, 'Got result', console.log(result.body.toString().substring(0,50) + '...'))
}
})
})
test('get / (promise style)', t => {
t.plan(1)
tiny.get({url})
.then(function win (result) {
t.ok(result, 'Got result:', console.log(result.body.toString().substring(0,50) + '...'))
})
.catch(function fail (err) {
t.fail(err)
})
})
test('get / (async/await style)', async t => {
t.plan(1)
try {
let result = await tiny.get({url})
t.ok(result, 'Got result:', console.log(result.body.toString().substring(0,50) + '...'))
} catch (err) {
t.fail(err)
}
})
test('Shut down sandbox', async t => {
t.plan(1)
let result = await sandbox.end()
t.equal(result, 'Sandbox successfully shut down')
})

View File

@@ -0,0 +1,125 @@
let test = require('tape')
let data = require('@begin/data')
let sandbox = require('@architect/sandbox')
let logJSON = i => console.log(JSON.stringify(i,null,2))
/**
* Begin Data test
* - Demonstrates basic usage of Begin Data, a fast, free, durable, wide-column persistence store already built into your app
*/
test('Set up env', t => {
t.plan(4)
t.ok(data, 'Begin Data loaded')
t.ok(data.get, 'data.get ready')
t.ok(data.set, 'data.set ready')
t.ok(data.destroy, 'data.destroy ready')
})
test('Start sandbox', async t=> {
t.plan(1)
let result = await sandbox.start()
t.ok(result, 'Sandbox started!')
})
test('data.set (one document)', async t => {
t.plan(1)
let result = await data.set({
table: 'tasks',
key: 'task1'
})
t.ok(result.key === 'task1', 'Wrote document')
logJSON(result,null,2)
})
test('data.get (one document)', async t => {
t.plan(1)
let task = await data.get({
table: 'tasks',
key: 'task1'
})
t.ok(task.key === 'task1', 'Read document')
logJSON(task,null,2)
})
test('data.destroy (one document)', async t => {
t.plan(1)
let result = await data.destroy({
table: 'tasks',
key: 'task1'
})
t.ok(result, 'Deleted document')
logJSON(result,null,2)
})
/**
* If no key is supplied, one is created automatically
*/
test('data.set generates a unique key', async t => {
t.plan(1)
let result = await data.set({
table: 'tasks'
})
t.ok(result.key, 'Saved document has a key')
logJSON(result,null,2)
})
/**
* Any (meta)data is allowed
*/
test('data.set allows for any JSON document; only table and key are reserved', async t => {
t.plan(1)
let result = await data.set({
table: 'tasks',
message: 'hello world',
complete: false,
timeframe: new Date(Date.now()).toISOString()
})
t.ok(Object.getOwnPropertyNames(result.key).length > 2, 'Saved document has multiple properties')
logJSON(result,null,2)
})
/**
* Save a batch of documents by passing an array
*/
test('data.set accepts an array to batch save documents', async t => {
t.plan(1)
let result = await data.set([{
table: 'tasks',
message: 'catch sunshine every day',
complete: true,
timeframe: new Date(Date.now()).toISOString()
},
{
table: 'tasks',
message: 'leave the phone at home on accident purpose',
complete: false,
timeframe: new Date(Date.now()).toISOString()
},
{
table: 'tasks',
message: 'walk the seawall',
complete: false,
timeframe: new Date(Date.now()).toISOString()
}])
t.equal(result.length, 3, 'Saved document batch')
logJSON(result,null,2)
})
/**
* Scan a table
*/
test('data.get can read an entire table', async t => {
t.plan(1)
let result = await data.get({
table: 'tasks'
})
t.ok(result.length > 1, 'Got docs')
logJSON(result,null,2)
})
test('Shut down sandbox', async t => {
t.plan(1)
let result = await sandbox.end()
t.equal(result, 'Sandbox successfully shut down')
})