UNPKG

878 BJavaScriptView Raw
1'use strict';
2
3const test = require('tape');
4const haikuist = require('./');
5
6test('fetch haikus', async t => {
7 t.plan(2);
8 const { posts } = await haikuist.fetchPosts();
9 const [post] = posts;
10 t.ok(posts.length > 0, 'haikus are fetched');
11 t.ok(post && post.id, `last haiku: id=${post.id}`);
12});
13
14test('fetch latest haiku', async t => {
15 t.plan(1);
16 const { posts } = await haikuist.fetchPosts();
17 const latestPost = await haikuist.fetchLatest();
18 t.equals(latestPost.id, posts[0].id, 'latest haiku fetched');
19});
20
21test('fetch random haiku', async t => {
22 t.plan(3);
23 const haiku1 = await haikuist.fetchRandom();
24 const haiku2 = await haikuist.fetchRandom();
25 t.ok(haiku1 && haiku1.id, `first haiku fetched: id=${haiku1.id}`);
26 t.ok(haiku2 && haiku2.id, `second haiku fetched: id=${haiku2.id}`);
27 t.notEquals(haiku1.id, haiku2.id, 'haikus are different');
28});