Implement easy parts of client

This commit is contained in:
Bret Comnes
2019-11-11 21:13:05 -07:00
parent b3281ddda5
commit 364b8fc2ed
11 changed files with 1927 additions and 31 deletions

51
test.js
View File

@@ -1,9 +1,44 @@
import tape from 'tape'
import ptape from 'tape-promise'
import { thing } from './main'
const test = ptape(tape)
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);
test('a test', async t => {
console.log(thing)
t.ok('pass')
})
let token = process.env.NEOCITIES_API_TOKEN;
if (!token) {
try {
const config = JSON.parse(readFileSync(resolve(__dirname, 'config.json')));
token = config.token;
} catch (e) {
console.warn('error loading config.json');
console.warn(e);
}
}
if (token) {
test('token loaded', async t => {
t.ok(token);
});
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');
});
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');
}