Skip to content

Commit

Permalink
fix: home context error
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Aug 6, 2019
1 parent 401f2cc commit be84838
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
6 changes: 4 additions & 2 deletions app/controller/home.js
Expand Up @@ -3,13 +3,15 @@
const {
Controller,
} = require('egg');
const safeGet = require('lodash/get');

class HomeController extends Controller {
async index() {
const ctx = this.ctx;
const user = ctx.session.user;
const { appid, callbackUrl } = ctx.app.config.authorize.dingtalkAuth;
const { data: configRes } = await this.ctx.model.Config.findOne({ raw: true });
const siteConfig = await this.ctx.model.Config.findOne({ raw: true });
const assetsUrl = safeGet(siteConfig, 'data.site.assetsUrl');
ctx.body = await this.app.render({
dingtalkAuth: {
appid,
Expand All @@ -20,7 +22,7 @@ class HomeController extends Controller {
title: 'Reliable Suites for Macaca',
pageId: 'home',
SERVER_ADDRESS: this.config.reliableView.serverUrl,
assetsUrl: configRes.site && configRes.site.assetsUrl || this.config.reliableView.assetsUrl,
assetsUrl: assetsUrl || this.config.reliableView.assetsUrl,
version: this.app.config.pkg.version,
});
}
Expand Down
30 changes: 20 additions & 10 deletions test/app/controller/home.test.js
@@ -1,18 +1,28 @@
'use strict';

const { app, assert } = require('egg-mock/bootstrap');
const { app } = require('egg-mock/bootstrap');

describe('test/app/controller/home.test.js', () => {

it('assert keys', () => {
const pkg = require('../../../package.json');
assert(app.config.keys.startsWith(pkg.name));
});
describe('GET /', () => {
it('should be ok', () => {
return app.httpRequest()
.get('/')
.expect(/Reliable Suites for Macaca/)
.expect(200);
});

it('GET /', () => {
return app.httpRequest()
.get('/')
.expect(/Reliable Suites for Macaca/)
.expect(200);
it('should be ok with site config', async () => {
const ctx = app.mockContext();
await ctx.model.Config.create({
data: {
site: {
assetsUrl: 'https://foo',
},
},
});
return app.httpRequest()
.get('/');
});
});
});

0 comments on commit be84838

Please sign in to comment.