提交 57e5e0f5 编写于 作者: YXL76's avatar YXL76

test: use axios

上级 cea20242
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const request = require('request')
let app let app
before(() => { before(() => {
app = require('./app.js') app = require('./app.js')
global.host = 'http://localhost:' + app.server.address().port global.host = 'http://localhost:' + app.server.address().port
request.debug = false
}) })
after((done) => { after((done) => {
app.server.close(done) app.server.close(done)
......
const assert = require('assert') const assert = require('assert')
const request = require('request') const axios = require('axios')
const host = global.host || 'http://localhost:3000' const host = global.host || 'http://localhost:3000'
describe('测试获取歌手专辑列表是否正常', () => { describe('测试获取歌手专辑列表是否正常', () => {
...@@ -8,14 +8,18 @@ describe('测试获取歌手专辑列表是否正常', () => { ...@@ -8,14 +8,18 @@ describe('测试获取歌手专辑列表是否正常', () => {
id: 32311, id: 32311,
} }
request.get({ url: `${host}/album`, qs: qs }, (err, res, body) => { axios
if (!err && res.statusCode == 200) { .get(`${host}/album`, {
body = JSON.parse(body) params: qs,
assert(body.code === 200) })
.then(({ status, data }) => {
if (status == 200) {
assert(data.code === 200)
}
done() done()
} else { })
.catch((err) => {
done(err) done(err)
} })
})
}) })
}) })
const assert = require('assert') const assert = require('assert')
const request = require('request') const axios = require('axios')
const host = global.host || 'http://localhost:3000' const host = global.host || 'http://localhost:3000'
describe('测试获取评论是否正常', () => { describe('测试获取评论是否正常', () => {
...@@ -8,14 +8,18 @@ describe('测试获取评论是否正常', () => { ...@@ -8,14 +8,18 @@ describe('测试获取评论是否正常', () => {
id: 32311, id: 32311,
} }
request.get({ url: `${host}/comment/album`, qs: qs }, (err, res, body) => { axios
if (!err && res.statusCode == 200) { .get(`${host}/comment/album`, {
body = JSON.parse(body) params: qs,
assert(body.code === 200) })
.then(({ status, data }) => {
if (status == 200) {
assert(data.code === 200)
}
done() done()
} else { })
.catch((err) => {
done(err) done(err)
} })
})
}) })
}) })
const assert = require('assert') const assert = require('assert')
const request = require('request') const axios = require('axios')
const host = global.host || 'http://localhost:3000' const host = global.host || 'http://localhost:3000'
console.log('注意: 测试登录需在 test/login.test.js 中填写账号密码!!!') console.log('注意: 测试登录需在 test/login.test.js 中填写账号密码!!!')
...@@ -12,18 +12,20 @@ describe('测试登录是否正常', () => { ...@@ -12,18 +12,20 @@ describe('测试登录是否正常', () => {
password: process.env.NCM_API_TEST_LOGIN_PASSWORD || password || '', password: process.env.NCM_API_TEST_LOGIN_PASSWORD || password || '',
} }
request.get( axios
{ url: `${host}/login/cellphone`, qs: qs }, .get(`${host}/login/cellphone`, {
(err, res, body) => { params: qs,
if (!err && res.statusCode == 200) { })
body = JSON.parse(body) .then(({ status, data }) => {
assert(body.code === 200) if (status == 200) {
console.log('昵称:' + body.profile.nickname) console.log('昵称:' + data.profile.nickname)
assert(data.code === 200)
done() done()
} else {
done('登录错误')
} }
}, done('登录错误')
) })
.catch((err) => {
done(err)
})
}) })
}) })
const assert = require('assert') const assert = require('assert')
const request = require('request') const axios = require('axios')
const host = global.host || 'http://localhost:3000' const host = global.host || 'http://localhost:3000'
describe('测试获取歌词是否正常', () => { describe('测试获取歌词是否正常', () => {
...@@ -8,14 +8,18 @@ describe('测试获取歌词是否正常', () => { ...@@ -8,14 +8,18 @@ describe('测试获取歌词是否正常', () => {
id: 347230, id: 347230,
} }
request.get({ url: `${host}/lyric`, qs: qs }, (err, res, body) => { axios
if (!err && res.statusCode == 200) { .get(`${host}/lyric`, {
body = JSON.parse(body) params: qs,
assert(typeof body.lrc !== 'undefined') })
.then(({ status, data }) => {
if (status == 200) {
assert(typeof data.lrc !== 'undefined')
}
done() done()
} else { })
.catch((err) => {
done(err) done(err)
} })
})
}) })
}) })
const assert = require('assert') const assert = require('assert')
const request = require('request') const axios = require('axios')
const host = global.host || 'http://localhost:3000' const host = global.host || 'http://localhost:3000'
describe('测试获取歌曲是否正常', () => { describe('测试获取歌曲是否正常', () => {
...@@ -9,14 +9,18 @@ describe('测试获取歌曲是否正常', () => { ...@@ -9,14 +9,18 @@ describe('测试获取歌曲是否正常', () => {
br: 999000, br: 999000,
} }
request.get({ url: `${host}/song/url`, qs: qs }, (err, res, body) => { axios
if (!err && res.statusCode == 200) { .get(`${host}/song/url`, {
body = JSON.parse(body) params: qs,
assert(!!body.data[0].url) })
.then(({ status, data }) => {
if (status == 200) {
assert(!!data.data[0].url)
}
done() done()
} else { })
.catch((err) => {
done(err) done(err)
} })
})
}) })
}) })
const assert = require('assert') const assert = require('assert')
const request = require('request') const axios = require('axios')
const host = global.host || 'http://localhost:3000' const host = global.host || 'http://localhost:3000'
describe('测试搜索是否正常', () => { describe('测试搜索是否正常', () => {
...@@ -8,14 +8,18 @@ describe('测试搜索是否正常', () => { ...@@ -8,14 +8,18 @@ describe('测试搜索是否正常', () => {
keywords: '海阔天空', keywords: '海阔天空',
type: 1, type: 1,
} }
request.get({ url: `${host}/search`, qs: qs }, (err, res, body) => { axios
if (!err && res.statusCode == 200) { .get(`${host}/search`, {
body = JSON.parse(body) params: qs,
assert(body.result.songs[0].name === '海阔天空') })
.then(({ status, data }) => {
if (status == 200) {
assert(data.result.songs[0].name === '海阔天空')
}
done() done()
} else { })
.catch((err) => {
done(err) done(err)
} })
})
}) })
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册