1 | 'use strict';
|
2 |
|
3 | const test = require('tape');
|
4 | const haikuist = require('./');
|
5 |
|
6 | test('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 |
|
14 | test('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 |
|
21 | test('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 | });
|