-
Notifications
You must be signed in to change notification settings - Fork 4
/
2.foreign.spec.ts
66 lines (62 loc) · 1.95 KB
/
2.foreign.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
59
60
61
62
63
64
65
66
import 'dotenv/config'
import { describe, it } from 'mocha'
import { expect } from 'chai'
import { env } from 'process'
import { MediaWikiForeignApi } from '../src/index'
;(globalThis as any).location = new URL('https://zh.moegirl.org.cn/Mainpage')
const api = new MediaWikiForeignApi('https://commons.moegirl.org.cn/api.php', {
headers: {
'api-user-agent': env.MOEGIRL_API_USER_AGENT || '',
origin: location.origin,
},
})
describe('MediaWikiForeignApi', () => {
it('[GET] siteinfo', async () => {
const { data, response } = await api
.get({
action: 'query',
meta: 'siteinfo',
})
.catch((e) => {
console.warn(e)
return Promise.reject(e)
})
expect(response.headers.get('access-control-allow-origin')).to.equal(
location.origin
)
expect(data.query.general.sitename).to.equal('萌娘共享')
})
it('[GET] array as param', async () => {
const { data, response } = await api.get({
action: 'query',
meta: ['siteinfo', 'userinfo'],
})
expect(response.headers.get('access-control-allow-origin')).to.equal(
location.origin
)
expect(data.query.general).to.not.be.undefined
expect(data.query.userinfo).to.not.be.undefined
})
it('[POST] parse', async () => {
const { data, response } = await api
.post({
action: 'parse',
title: 'Custom Page',
text: `'''bold''' ''italic'' [[Mainpage]] {{PAGENAME}}`,
prop: ['text', 'wikitext', 'links'],
disablelimitreport: 1,
})
.catch((e) => {
console.warn(e)
return Promise.reject(e)
})
// console.info({ data, headers })
expect(response.headers.get('access-control-allow-origin')).to.equal(
location.origin
)
expect(data.parse.title).to.eq('Custom Page')
expect(data.parse.text).to.includes('<b>bold</b>')
expect(data.parse.text).to.includes('<i>italic</i>')
expect(data.parse.links).to.be.an('array')
})
})