Switch back over to CJS. sa la vie

This commit is contained in:
Bret Comnes
2019-12-26 16:50:42 -07:00
parent 364b8fc2ed
commit abc9656e71
11 changed files with 183 additions and 1841 deletions

102
test.js
View File

@@ -1,44 +1,82 @@
import tape from 'tape';
import ptape from 'tape-promise';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { NeocitiesAPIClient } from './lib/client.js';
const test = ptape(tape);
const tap = require('tap')
let token = process.env.NEOCITIES_API_TOKEN;
const { readFileSync } = require('fs')
const { resolve } = require('path')
const { NeocitiesAPIClient } = require('./lib/client')
let token = process.env.NEOCITIES_API_TOKEN
if (!token) {
try {
const config = JSON.parse(readFileSync(resolve(__dirname, 'config.json')));
token = config.token;
const config = JSON.parse(readFileSync(resolve(__dirname, 'config.json')))
token = config.token
} catch (e) {
console.warn('error loading config.json');
console.warn(e);
console.warn('error loading config.json')
console.warn(e)
}
}
if (token) {
test('token loaded', async t => {
t.ok(token);
});
tap.test('token loaded', async t => {
t.ok(token)
})
test('basic client api', async t => {
const client = new NeocitiesAPIClient(token);
tap.test('basic client api', async t => {
const client = new NeocitiesAPIClient(token)
t.ok(client.info, 'info method available');
t.ok(client.list, 'list method available');
t.ok(client.get, 'get method available');
t.ok(client.post, 'post method available');
});
t.ok(client.info, 'info method available')
t.ok(client.list, 'list method available')
t.ok(client.get, 'get method available')
t.ok(client.post, 'post method available')
})
test('can get info about site', async t => {
const client = new NeocitiesAPIClient(token);
tap.test('can get info about site', async t => {
const client = new NeocitiesAPIClient(token)
const info = await client.info();
console.log(info);
const list = await client.list();
console.log(list);
});
} else {
console.warn('No token set, live tests disabled');
}
const info = await client.info()
console.log(info)
t.equal(info.result, 'success', 'info requesst successfull')
const list = await client.list()
console.log(list)
t.equal(list.result, 'success', 'list result successfull')
})
// test('form data works the way I think', t => {
// const form = new FormData();
// const p = resolve(__dirname, 'package.json');
// form.append('package.json', next => next(createReadStream(p)));
//
// const concatStream = concat((data) => {
// console.log(data);
// t.end();
// });
//
// form.on('error', (err) => {
// t.error(err);
// });
// form.pipe(concatStream);
// });
tap.test('can upload and delete files', async t => {
const client = new NeocitiesAPIClient(token)
const uploadResults = await client.upload([
{
name: 'toot.gif',
path: resolve(__dirname, 'fixtures/toot.gif')
},
{
name: 'img/tootzzz.png',
path: resolve(__dirname, 'fixtures/tootzzz.png')
}
])
console.log(uploadResults)
t.equal(uploadResults.result, 'success', 'list result successfull')
const deleteResults = await client.delete([
'toot.gif',
'img/tootzzz.png'
])
console.log(deleteResults)
t.equal(deleteResults.result, 'success', 'list result successfull')
})