-
Notifications
You must be signed in to change notification settings - Fork 4
/
4.actions.spec.ts
58 lines (52 loc) · 1.46 KB
/
4.actions.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import 'dotenv/config'
import { describe, it } from 'mocha'
import { expect } from 'chai'
import { env } from 'process'
import { MediaWikiApi } from '../src/index'
const api = new MediaWikiApi('https://zh.moegirl.org.cn/api.php', {
headers: {
'api-user-agent': env.MOEGIRL_API_USER_AGENT || '',
},
})
const username = env.MOEGIRL_USERNAME || ''
const password = env.MOEGIRL_PASSWORD || ''
const now = new Date()
const editTitle = `User:${username}/sandbox/wiki-saikou`
let editPageid = 0
let editNewrevid = 0
describe('Actions', () => {
it('Login', async () => {
const login = await api.login(username, password)
expect(login.result).to.equal('Success')
})
it('Do edit', async () => {
const {
data: { edit },
} = await api.postWithEditToken({
action: 'edit',
title: editTitle,
text: now.toISOString(),
summary: '[Automatic] Unit tests for https://npm.im/wiki-saikou',
})
expect(edit.result).to.equal('Success')
editPageid = edit.pageid
editNewrevid = edit.newrevid
})
it('Check edit contents', async () => {
const {
data: {
query: {
pages: [page],
},
},
} = await api.get({
action: 'query',
revids: editNewrevid,
prop: 'revisions',
rvprop: 'user|content',
})
expect(page.pageid).to.equal(editPageid)
expect(page.revisions[0].user).to.equal(username)
expect(page.revisions[0].content).to.equal(now.toISOString())
})
})