From cc8e46d998ab1d368a6d1c39668103d6c9526f07 Mon Sep 17 00:00:00 2001 From: kingweicai Date: Mon, 15 Oct 2018 11:17:26 +0800 Subject: [PATCH] feat: add a test case for isAlphaUin func --- bin/proxy/websocket.js | 2 ++ test/bin/tsw/util/alpha.test.js | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/bin/proxy/websocket.js b/bin/proxy/websocket.js index ed7e22fa..bec5e5e7 100644 --- a/bin/proxy/websocket.js +++ b/bin/proxy/websocket.js @@ -277,12 +277,14 @@ exports.start_listen = function() { const ws = new WSServer({ server: global.TSW_HTTP_SERVER }); + global.TSW_WS_SERVER = ws; bind_listen(ws); if (global.TSW_HTTPS_SERVER) { const wss = new WSServer({ server: global.TSW_HTTPS_SERVER }); + global.TSW_WSS_SERVER = ws; bind_listen(wss); } }; diff --git a/test/bin/tsw/util/alpha.test.js b/test/bin/tsw/util/alpha.test.js index c094df7c..040f6cf3 100644 --- a/test/bin/tsw/util/alpha.test.js +++ b/test/bin/tsw/util/alpha.test.js @@ -52,6 +52,49 @@ describe('test tsw/util/alpha', () => { }); }); + describe('#isAlphaUin', () => { + + it('#check a num not skymode', () => { + config.skyMode = false; + const uid = 1; + expect(alpha.isAlpha(uid)).to.be.equal(undefined); + }); + + it('#update', () => { + alpha.update({ 1: true }); + const uid = 1; + expect(alpha.isAlpha(uid)).to.be.equal(true); + }); + + it('#get From logger', () => { + alpha.update({ 1: true }); + + const stub = sinon.stub(logger, 'getKey').callsFake(() => { + return 1; + }); + + expect(alpha.isAlpha()).to.be.equal(true); + stub.restore(); + }); + + it('#get From getUin', () => { + alpha.update({ 1: true }); + context.window = { + request: {} + }; + config.extendMod = { + getUid: (req) => { + return 1; + } + }; + + expect(alpha.isAlpha()).to.be.equal(true); + delete context.window; + delete config.extendMod; + }); + }); + + describe('#getUin', () => { it('#without req', () => { expect(alpha.getUin()).to.be.equal(undefined);