Skip to content

Commit

Permalink
Merge aba0d0c into 39d4333
Browse files Browse the repository at this point in the history
  • Loading branch information
Nkemjiks committed Jul 19, 2018
2 parents 39d4333 + aba0d0c commit 1eb16eb
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 15 deletions.
20 changes: 20 additions & 0 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,25 @@ const user = (req, res, next, id) => {
});
};

/**
* @param {object} req - request object provided by express
* @param {object} res - response object provided by express
* @param {function} next - next function for passing the request to next handler
* @description finds a user by id from the db and
* updates the tour field to true
*/
const updateUserTour = (req, res, next) => {
const { id } = req.params;
User.findOneAndUpdate(
{ _id: id },
{ tour: true },
(err) => {
if (err) return next(err);
return res.status(200).send({ tourUpdated: true });
}
);
};

/**
* @param {object} req - request object provided by express
* @param {object} res - response object provided by express
Expand Down Expand Up @@ -349,6 +368,7 @@ const invite = (req, res) => {
export default {
authCallback,
user,
updateUserTour,
me,
show,
addDonation,
Expand Down
1 change: 1 addition & 0 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const UserSchema = new Schema({
username: String,
provider: String,
avatar: String,
tour: { type: Boolean, default: false },
premium: Number, // null or 0 for non-donors, 1 for everyone else (for now)
donations: [],
hashed_password: String,
Expand Down
5 changes: 4 additions & 1 deletion app/views/includes/foot.jade
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ script(type='text/javascript', src='/js/controllers/header.js')
script(type='text/javascript', src='/js/controllers/game.js')
script(type='text/javascript', src='/js/controllers/auth.js')
script(type='text/javascript', src='/js/controllers/invitePlayers.js')
script(type='text/javascript', src='/js/controllers/tour.js')
script(type='text/javascript', src='/js/init.js')

//Introjs
script(type='text/javascript', src='https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.9.3/intro.min.js')

// Application components
script(type='text/javascript', src='/js/directives/profile.js')


//Socket.io Client Library
script(type='text/javascript', src='/socket.io/socket.io.js')

Expand Down
2 changes: 2 additions & 0 deletions app/views/includes/head.jade
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ head
link(href='https://res.cloudinary.com/dqsmurjpg/image/upload/v1530719572/logo.jpg', rel='shortcut icon', type='image/x-icon')
link(href='https://fonts.googleapis.com/css?family=Lobster', rel='stylesheet', type='text/css')
link(rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous")
link(href='https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.9.3/introjs.min.css', rel='stylesheet', type='text/css')
link(href="https://fonts.googleapis.com/icon?family=Material+Icons", rel="stylesheet")

meta(property='fb:app_id', content='APP_ID')
meta(property='og:title', content='#{appName} - #{title}')
Expand Down
16 changes: 15 additions & 1 deletion backend-test/startGame/startGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const userMock = {
};

let token = '';
let id = '';
describe('Player endpoints', () => {
before(() => {
Promise.resolve(User.create(userMock, (err, user) => {
Expand All @@ -40,11 +41,12 @@ describe('Player endpoints', () => {
expect(res.statusCode).to.equal(200);
/* eslint prefer-destructuring: 0 */
token = res.body.token;
id = res.body._id;
done();
});
});

it('POST /api/game/:id/start endpoint should return the the game players', (done) => {
it('POST /api/game/:id/start endpoint should return the the game players', (done) => {
request(app)
.post('/api/game/3/start')
.set('authorization', token)
Expand All @@ -56,4 +58,16 @@ describe('Player endpoints', () => {
done();
});
});

it('POST /api/tour/:id endpoint should update the tour option to true', (done) => {
request(app)
.post(`/api/tour/${id}`)
.set('authorization', token)
.end((err, res) => {
if (err) return done(err);
expect(res.statusCode).to.equal(200);
expect(res.body.tourUpdated).to.equal(true);
done();
});
});
});
4 changes: 4 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default (router, passport, app) => {
.get('/profile', ensureUser, users.fetchProfile)
.post('/game/:id/start', ensureUser, game);

// Setting up user tour api
api
.post('/tour/:id', users.updateUserTour);

router.get('/signin', users.signin);
router.get('/signup', users.signup);
router.get('/chooseavatars', users.checkAvatar);
Expand Down
54 changes: 54 additions & 0 deletions frontend-test/angular/tour.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint prefer-arrow-callback: 0, func-names: 0, no-undef: 0 */
describe('Tour', function () {
let $scope, $http, $httpBackend, controller;
beforeEach(module('mean.system'));
beforeEach(inject(function (_$controller_, _$httpBackend_, _$http_, _$rootScope_) {
$scope = _$rootScope_.$new();
$http = _$http_;
controller = _$controller_;
$httpBackend = _$httpBackend_;
controller('TourController', {
$scope,
$http
});
}));

beforeEach(function () {
const store = {};
spyOn(localStorage, 'getItem').and.callFake(function (key) {
return store[key];
});
spyOn(localStorage, 'setItem').and.callFake(function (key, value) {
store[key] = `${value}`;
return store[key];
});
localStorage.setItem('#cfhetUserId', '1233jjfjf');
});

it('Update the tour option in the database and update localstorage', function () {
const tourUpdate = { tourUpdate: 'true' };

$httpBackend.whenPOST('/api/tour/1233jjfjf').respond(function () {
return tourUpdate;
}());

$scope.updateTour().then(() => {});

$httpBackend.flush();
expect(localStorage.getItem('#cfhuseristourtaken')).toEqual(tourUpdate.tourUpdate);
});

it('Should close the tour modal', function () {
spyOn($scope, 'closeTourModal').and.callThrough();
expect($scope.closeTourModal).toBeDefined();
});

it('Should call the takeTour method', function () {
spyOn($scope, 'takeNewUserTour').and.callThrough();
spyOn($scope, 'takeGeneralTour').and.callThrough();
spyOn($scope, 'tour').and.callThrough();
expect($scope.takeNewUserTour).toBeDefined();
expect($scope.takeGeneralTour).toBeDefined();
expect($scope.tour).toBeDefined();
});
});
37 changes: 36 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,19 @@ i {
box-shadow: none;
}

#tour-button {
box-shadow: none;
color: #000 !important;
background-color: transparent !important;
}

#tour-button:hover {
border: 2px solid black;
border-radius: 3px;
background-color: white !important;
color: black !important;
}

#index-login-btn {
border: 2px solid black;
border-radius: 3px;
Expand Down Expand Up @@ -384,6 +397,20 @@ i {
color: black !important;
}

#tour-chioce-btn {
color: white;
background-color: #236231 !important;
border: 0;
padding: 0 !important;
}

#tour-chioce-btn:hover {
border: 2px solid black;
border-radius: 3px;
background-color: white !important;
color: black !important;
}


.avatars {
position: relative;
Expand Down Expand Up @@ -786,7 +813,7 @@ i {
}

@media screen and (max-width: 425px) {
.abandon-button {
.navbar-button {
height: 30px !important;
line-height: 30px !important;
padding: 0 5px !important;
Expand Down Expand Up @@ -992,4 +1019,12 @@ i {
border-radius: 3px;
padding: 8px;
font-size: 0.9375rem;
}

nav .sidenav-trigger {
float: right !important;
}

.sidenav-trigger > i {
color: #236231 !important;
}
11 changes: 9 additions & 2 deletions public/js/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ angular.module('mean.system')
localStorage.removeItem('#cfhetusertoken');
localStorage.removeItem('username');
localStorage.removeItem('#cfhetUserId');
localStorage.removeItem('#cfhuseristourtaken');
};

$scope.username = localStorage.getItem('username');
Expand All @@ -37,6 +38,7 @@ angular.module('mean.system')
localStorage.setItem('#cfhetusertoken', response.token);
localStorage.setItem('#cfhetUserId', response._id);
localStorage.setItem('username', response.name);
localStorage.setItem('#cfhuseristourtaken', response.tour);
$location.path('/');
}, (error) => {
$scope.authError = error.data.message;
Expand All @@ -48,9 +50,14 @@ angular.module('mean.system')
localStorage.setItem('#cfhetusertoken', response.token);
localStorage.setItem('#cfhetUserId', response._id);
localStorage.setItem('username', response.name);
localStorage.setItem('#cfhuseristourtaken', response.tour);
$location.path('/');
}, () => {
$scope.authError = 'Please check your username/password and try again';
}, (error) => {
if (error.data.message === 'Unknown user') {
$scope.authError = 'Oops, We can not find you in our system';
} else {
$scope.authError = 'Please check your email/password and try again';
}
});
};
}]);
2 changes: 1 addition & 1 deletion public/js/controllers/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ angular.module('mean.system')
$('.modal-header').empty();
refusableModel.find('.modal-header').append('<h4 class="modal-title center-align" style="color: #23522d;">3 PLAYERS REQUIRED</h4>');
refusableModel.find('.modal-body').text('This game requires a minimum of 3 players. Please invite more friends to play');
var okayBtn = '<button type="button" class="btn waves-effect waves-green modal-close" id="play-chioce-btn">OKAY</button>';
var okayBtn = '<button type="button" class="btn waves-effect waves-green modal-close" id="play-chioce-btn">OKAY</button>';
$('.modal-footer').empty();
$('.modal-footer').append(okayBtn);
$('#reuse-modal').modal('open');
Expand Down
108 changes: 108 additions & 0 deletions public/js/controllers/tour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* eslint prefer-arrow-callback: 0, func-names: 0, no-undef: 0, no-var: 0,
vars-on-top: 0, require-jsdoc: 0 */

angular.module('mean.system')
.controller('TourController', ['$scope', '$http', function ($scope, $http) {
var token = localStorage.getItem('#cfhetusertoken');

$scope.closeTourModal = function () {
$('#tour-modal').modal('close');
$scope.updateTour();
};

const steps = [
{
intro: 'Welcome to the gaming screen for Cards for Humanity. This tour will give you a brief introduction to how to play the game.',
},
{
element: document.querySelector('#player'),
intro: 'Here are the instructions on how to play the game. If you are an authenticated user, you have the option to invite friends to play with you.',
position: 'top',
},
{
intro: 'Click on the abandon game button if you want to abandon a game. And the take a tour button if you would like to take a tour again.',
position: 'left'
},
{
element: document.querySelector('#timer-container'),
intro: 'Here is the timer. It counts down from 20s when choosing a card, from 15s when the Czar is making a decision and 4s when another round is about to begin.',
position: 'right'
},
{
element: document.querySelector('#social-bar-container'),
intro: 'Here is a display of all the players that are part of the game. You can also see each person score during the game.',
position: 'bottom'
},
{
element: document.querySelector('#social-bar-container'),
intro: 'An icon besides the score is used to show that the card is yours.',
position: 'right'
},
{
element: document.querySelector('#social-bar-container'),
intro: 'A Czar text will appear under the score text to identify who the czar is.',
position: 'right'
},
{
element: document.querySelector('#question-container-outer'),
intro: 'This shows you how many players have joined the game. You can click on the start game icon when the number of players is at least 3.',
position: 'bottom'
},
{
element: document.querySelector('#question-container-outer'),
intro: 'The questions are displayed here also as well as the final answer when Czar makes a choice.',
position: 'bottom'
},
{
element: document.querySelector('#player'),
intro: 'When a game is in session, a deck of 10 answer cards is displayed here for you to pick from if you not the Czar.',
position: 'top',
},
{
element: document.querySelector('#player'),
intro: 'If you are the Czar, some Make-a-Wish facts will be displayed to you while you wait for others to chose their answers.',
position: 'top',
},
{
element: document.querySelector('#player'),
intro: 'At the end of the game, a donation link is provided for you to make a donation to Make-a-Wish foundation if you want to.',
position: 'top',
},
{
intro: 'You can also chat with other players will the game is on with this chatbox. Simply click on the chatbox to toggle it open or close.',
position: 'top',
},
{
element: document.querySelector('#question-container-outer'),
intro: 'You can click on the start game icon if the number of players is at least 3 to start the game.',
position: 'bottom'
},
];

$scope.tour = function () {
const intro = introJs();
intro.setOptions({
steps,
exitOnOverlayClick: false
});
intro.start();
};

$scope.takeNewUserTour = function () {
$scope.tour();
$scope.updateTour();
};

$scope.takeGeneralTour = function () {
$scope.tour();
};

$scope.updateTour = function () {
const id = localStorage.getItem('#cfhetUserId');
return $http.post(`/api/tour/${id}`, { headers: { Authorization: `Bearer ${token}` } }).then(function (response) {
localStorage.setItem('#cfhuseristourtaken', true);
}, function (error) {
return error;
});
};
}]);
Loading

0 comments on commit 1eb16eb

Please sign in to comment.