chore: point miniapp API to deployed hera service
This commit is contained in:
1 parent
5be2ca6b50
commit
bc7bbc52c8
5 files changed
+39
-7
No files matched your search
@@ -28,7 +28,7 @@ test('编辑页所有编译样式均限定页面,默认头像不复用我的
|
||||
assert.doesNotMatch(source, /className='water-mascot'/)
|
||||
})
|
||||
|
||||
function setup(token = 'test-session') {
|
||||
function setup(token = 'test-session', baseUrl) {
|
||||
let profile = { ...fullProfile }
|
||||
const storage = { token }
|
||||
const calls = [], routes = []
|
||||
@@ -57,6 +57,7 @@ function setup(token = 'test-session') {
|
||||
vm.runInNewContext(ts.transpileModule(fs.readFileSync(path.join(root, `src/${name}.ts`), 'utf8'), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2019 }
|
||||
}).outputText, { exports, process: { env: { TARO_ENV: 'h5' } }, window: { location: { search: '' } }, URLSearchParams,
|
||||
...(baseUrl === undefined ? {} : { API_BASE_URL: baseUrl }),
|
||||
require: id => id === '@tarojs/taro' ? taro : load(path.posix.normalize(path.posix.join(path.posix.dirname(name), id))) })
|
||||
return exports
|
||||
}
|
||||
@@ -86,7 +87,7 @@ test('头像经专用COS后端接口上传,Bearer字段正确,禁止H5跨域
|
||||
ctx.service.subscribeProfile(profile => updates.push(profile))
|
||||
const profile = await ctx.service.api.uploadAvatar('blob:local-avatar')
|
||||
const upload = ctx.calls[0]
|
||||
assert.equal(upload.url, 'http://127.0.0.1:8080/api/user/avatar')
|
||||
assert.equal(upload.url, 'http://101.43.139.56/hera/api/user/avatar')
|
||||
assert.equal(upload.name, 'file')
|
||||
assert.equal(upload.filePath, 'blob:local-avatar')
|
||||
assert.equal(upload.header.Authorization, 'Bearer test-session')
|
||||
@@ -98,6 +99,23 @@ test('头像经专用COS后端接口上传,Bearer字段正确,禁止H5跨域
|
||||
assert.equal(ctx.calls.length, 1)
|
||||
})
|
||||
|
||||
test('默认部署地址为远端hera前缀,登录资料上传与相对文件路径一致且允许本地覆盖', async () => {
|
||||
const ctx = setup()
|
||||
await ctx.service.api.profile()
|
||||
await ctx.service.api.wxLogin('stub-code')
|
||||
assert.equal(ctx.calls[0].url, 'http://101.43.139.56/hera/api/user/profile')
|
||||
assert.equal(ctx.calls[1].url, 'http://101.43.139.56/hera/api/auth/wx-login')
|
||||
assert.equal(ctx.service.resolveAssetUrl('/file/access?token=test-only'), 'http://101.43.139.56/hera/file/access?token=test-only')
|
||||
assert.equal(ctx.service.resolveAssetUrl('https://files.example.test/image.png'), 'https://files.example.test/image.png')
|
||||
const local = setup('local-session', 'http://127.0.0.1:8080/')
|
||||
await local.service.api.profile()
|
||||
await local.service.api.uploadAvatar('blob:test-only')
|
||||
assert.equal(local.calls[0].url, 'http://127.0.0.1:8080/api/user/profile')
|
||||
assert.equal(local.calls[1].url, 'http://127.0.0.1:8080/api/user/avatar')
|
||||
const config = fs.readFileSync(path.join(root, 'config/index.ts'), 'utf8')
|
||||
assert.match(config, /process\.env\.HERA_API_BASE_URL \|\| 'http:\/\/101\.43\.139\.56\/hera'/)
|
||||
})
|
||||
|
||||
test('上传失败不覆盖已有头像;HTML 401也清理会话', async () => {
|
||||
const ctx = setup()
|
||||
await ctx.service.api.profile()
|
||||
|
||||
Reference in new issue
Block a user