Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chralp committed Sep 26, 2020
1 parent cdba6f5 commit 521669a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const config = {
themeName: getThemeName(),
themePath: getThemePath(),
},
level: {
enableLevel: getBool(process.env.ENABLE_LEVEL, false),
scoreRotation: getNum(process.env.SCORE_ROTATION, 500)
},
misc: {
slackMock: false,
log_level: process.env.LOG_LEVEL || 'info'
Expand Down Expand Up @@ -149,6 +153,10 @@ const config = {
themeName: getThemeName(),
themePath: getThemePath(),
},
level: {
enableLevel: getBool(process.env.ENABLE_LEVEL, false),
scoreRotation: getNum(process.env.SCORE_ROTATION, 500)
},
misc: {
slackMock: true,
},
Expand Down
12 changes: 9 additions & 3 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import mapper from './lib/mapper';
import { sort } from './lib/utils';
import BurritoStore from './store/BurritoStore';


const {
enableLevel,
scoreRotation,
} = config.level;

/**
* Middleware for API and Websocket
*/
Expand Down Expand Up @@ -36,11 +42,11 @@ const getScoreBoard = async (listType: string, scoreType: string) => {
return undefined;
}).filter((y) => y);

if(config.level.enableLevel) {
if(enableLevel) {
const levelScoreList = scoreList.map(x => {
let score = x.score;
const threshold = 5;
const roundedScore = Math.floor( score / threshold ) * 5;
const threshold: number = scoreRotation;
const roundedScore = Math.floor( score / threshold ) * threshold;
const level = Math.floor((score -1) / threshold)
const newScore = ((score - roundedScore) === 0 ? roundedScore - (score - threshold) : score - roundedScore);
return {
Expand Down
5 changes: 4 additions & 1 deletion test/middleware-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const proxyquire = require('proxyquire').noCallThru();
let getScoreBoard: any, getUserStats: any, givenBurritosToday: any, getUserScore: any

const loadMiddleware = ({ enable_decrement }) => {
const funcs = proxyquire('../src/middleware', { './config': { slack: { enableDecrement: enable_decrement } } });
const funcs = proxyquire('../src/middleware', { './config': {
slack: { enableDecrement: enable_decrement },
level: { enableLevel: false, scoreRotation: 500 }
} });
getScoreBoard = funcs.getScoreBoard
getUserStats = funcs.getUserStats
getUserScore = funcs.getUserScore
Expand Down

0 comments on commit 521669a

Please sign in to comment.