-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
187 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import assert from 'assert'; | ||
import pttbot from '../src'; | ||
import { username, password } from './config'; | ||
import { Article } from '../src/sites/ptt/model'; | ||
|
||
const newbot = async () => { | ||
const ptt = new pttbot(); | ||
await (() => new Promise(resolve => { | ||
ptt.once('connect', resolve); | ||
}))(); | ||
const ret = await ptt.login(username, password); | ||
if (!ret) { | ||
throw 'login failed'; | ||
} | ||
return ptt; | ||
}; | ||
|
||
const getArticleInfo = (article: Article) => { | ||
return `${article.id} ${article.author} ${article.title}`; | ||
}; | ||
|
||
describe('Article', () => { | ||
let ptt; | ||
before('login', async () => { | ||
ptt = await newbot(); | ||
}); | ||
after('logout', async () => { | ||
await ptt.logout(); | ||
}); | ||
|
||
describe('get', () => { | ||
let articles: Article[]; | ||
const boardname = 'Gossiping'; | ||
it('should get correct article list from board', async () => { | ||
articles = | ||
await ptt.select(Article) | ||
.where('boardname', boardname) | ||
.get(); | ||
assert(articles.length > 0); | ||
}); | ||
it('should get correct article list with "id" argument', async () => { | ||
let articles2: Article[] = | ||
await ptt.select(Article) | ||
.where('boardname', boardname) | ||
.where('id', articles[articles.length-1].id-1) | ||
.get(); | ||
|
||
const article1Info = getArticleInfo(articles[articles.length-1]); | ||
const article2Info = getArticleInfo(articles2[0]); | ||
assert.equal(articles2[0].id, articles[articles.length-1].id-1, `${article1Info}\n${article2Info}`); | ||
}); | ||
}); | ||
|
||
describe('getOne', () => { | ||
const boardname = 'Gossiping'; | ||
it('should get correct article from board', async () => { | ||
const article: Article = | ||
await ptt.select(Article) | ||
.where('boardname', boardname) | ||
.where('id', 100000) | ||
.getOne(); | ||
|
||
assert.strictEqual(article.boardname, boardname); | ||
assert.strictEqual(article.id, 100000); | ||
}); | ||
}); | ||
|
||
describe('where', () => { | ||
let board = 'Gossiping'; | ||
let push = '50'; | ||
let title = '問卦'; | ||
let author = 'kevin'; | ||
|
||
it('should get correct articles with specified push number from board', async () => { | ||
const articles: Article[] = | ||
await ptt.select(Article) | ||
.where('boardname', board) | ||
.where('push', push) | ||
.get(); | ||
assert(articles.length > 0); | ||
|
||
articles.forEach(article => { | ||
let pushCheck = false; | ||
let articleInfo = getArticleInfo(article); | ||
let pushNumber = (article.push === '爆') ? '100' : article.push; | ||
assert(Number(pushNumber) >= Number(push), articleInfo); | ||
}); | ||
}); | ||
|
||
it('should get correct articles with specified author name from board', async () => { | ||
const articles: Article[] = | ||
await ptt.select(Article) | ||
.where('boardname', board) | ||
.where('author', author) | ||
.get(); | ||
assert(articles.length > 0); | ||
|
||
articles.forEach(article => { | ||
let articleInfo = getArticleInfo(article); | ||
assert(article.author.toLowerCase().includes(author.toLowerCase()), articleInfo); | ||
}); | ||
}); | ||
|
||
it('should get correct articles contain specified title word from board', async () => { | ||
const articles: Article[] = | ||
await ptt.select(Article) | ||
.where('boardname', board) | ||
.where('title', title) | ||
.get(); | ||
assert(articles.length > 0); | ||
|
||
articles.forEach(article => { | ||
let articleInfo = getArticleInfo(article); | ||
assert(article.title.toLowerCase().includes(title), articleInfo); | ||
}); | ||
}); | ||
|
||
it('should get correct articles contain specified title word AND push number from board', async () => { | ||
const articles: Article[] = | ||
await ptt.select(Article) | ||
.where('boardname', board) | ||
.where('title', title) | ||
.where('push', push) | ||
.get(); | ||
assert(articles.length > 0); | ||
|
||
articles.forEach(article => { | ||
let articleInfo = getArticleInfo(article); | ||
let pushNumber = (article.push === '爆') ? '100' : article.push; | ||
assert(article.title.toLowerCase().includes(title), articleInfo); | ||
assert(Number(pushNumber) >= Number(push), articleInfo); | ||
}); | ||
}); | ||
}) | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import assert from 'assert'; | ||
import pttbot from '../src'; | ||
import { username, password } from './config'; | ||
import { Board } from '../src/sites/ptt/model'; | ||
|
||
const newbot = async () => { | ||
const ptt = new pttbot(); | ||
await (() => new Promise(resolve => { | ||
ptt.once('connect', resolve); | ||
}))(); | ||
const ret = await ptt.login(username, password) | ||
if (!ret) { | ||
throw 'login failed'; | ||
} | ||
return ptt; | ||
}; | ||
|
||
describe('Board', () => { | ||
let ptt; | ||
|
||
describe('get', () => { | ||
before('login', async () => { | ||
ptt = await newbot(); | ||
}); | ||
after('logout', async () => { | ||
await ptt.logout(); | ||
}); | ||
it('should get class list', async () => { | ||
let boards: Board[] = | ||
await ptt.select(Board) | ||
.where('entry', 'all') | ||
.get(); | ||
assert(boards.length > 0); | ||
}); | ||
it('should get hot list', async () => { | ||
let boards: Board[] = | ||
await ptt.select(Board) | ||
.where('entry', 'hot') | ||
.get(); | ||
assert(boards.length > 0); | ||
}); | ||
it('should get favorite list', async () => { | ||
let boards: Board[] = | ||
await ptt.select(Board) | ||
.where('entry', 'favorite') | ||
.get(); | ||
assert(boards.length > 0); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters