Skip to content

Commit

Permalink
fix: remove user interface (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored Apr 16, 2019
1 parent e904464 commit 3414384
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 58 deletions.
25 changes: 0 additions & 25 deletions lib/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const assert = require('assert');

class User {
constructor({ client }) {
this.client = client;
Expand All @@ -16,29 +14,6 @@ class User {
const api = login ? `users/${login}` : 'user';
return this.client.request(api, { method: 'GET' });
}

/**
* list all docs created by yourself
* @param {Object} [data] - query
* @param {String} [data.q] - fuzzy search doc title
* @param {Number} [data.offset] - limit offset, each page is 20.
* @return {Promise<DocInfo[]>} return docs
*/
async listDocs(data) {
return this.client.request('user/docs', { method: 'GET', data });
}

/**
* list recent updated
* @param {Object} data - query
* @param {String} data.type - repo type, `Book` / `Design` / `Column`
* @param {Number} [data.offset] - limit offset, each page is 20.
* @return {Array<DocInfo|RepoInfo>} return docs or books
*/
async listRecentUpdated(data) {
assert(data && data.type, '`data.type` is required');
return this.client.request('user/recent-updated', { method: 'GET', data });
}
}

module.exports = User;
6 changes: 4 additions & 2 deletions test/docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ describe('test/docs.test.js', () => {
});

it('should create and delete', async () => {
const slug = `unittest_create_${Date.now()}`;
const title = `a doc auto created by unittest(${Date.now()})`;
const data = await client.docs.create({
namespace,
data: {
title,
slug: 'unittest_create',
slug,
public: 1,
body: '**auto created by unittest, this is body**',
},
});
assert(data.title === title);
assert(data.slug === slug);
assert(data.body.includes('auto created by unittest'));

const deleteData = await client.docs.delete({ namespace, id: data.id });
assert(deleteData.slug === 'unittest_create');
assert(deleteData.slug === slug);
assert(deleteData.title === title);
});

Expand Down
31 changes: 0 additions & 31 deletions test/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,4 @@ describe('test/user.test.js', () => {
const data = await client.users.get();
assert(data.id === 201213);
});

it('should listDocs', async () => {
const data = await client.users.listDocs();
assert(data.length >= 1);
assert(data[0].slug);
});

it('should listDocs', async () => {
const data = await client.users.listDocs();
assert(data.length >= 1);
assert(data[0].slug);
});

it('should listDocs by title', async () => {
const data = await client.users.listDocs({ q: 'Quick' });
assert(data.length >= 1);
const list = data.map(x => x.slug);
assert(list.includes('quickstart'));
});

it('should listRecentUpdated Doc', async () => {
const data = await client.users.listRecentUpdated({ type: 'Doc' });
assert(data.length >= 1);
assert(data[0].book_id);
});

it('should listRecentUpdated Book', async () => {
const data = await client.users.listRecentUpdated({ type: 'Book' });
assert(data.length >= 1);
assert(data[0].type === 'Book');
});
});

0 comments on commit 3414384

Please sign in to comment.