Skip to content

Commit

Permalink
Merge pull request #27 from YashdalfTheGray/master
Browse files Browse the repository at this point in the history
Merging master into stable for release milestone
  • Loading branch information
YashdalfTheGray committed May 28, 2015
2 parents 1d36ea7 + c54bfae commit 1a31d5c
Show file tree
Hide file tree
Showing 27 changed files with 1,402 additions and 158 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ This will reduce the ammount of conflicts rising from versioning and previous ex

To run the website server, execute `gulp start` from a terminal window. Then navigate to http://localhost:8080.

## Testing

To run the client side tests, execute `gulp test:client` from a terminal window.

## Linting

Running `gulp jshint` will lint any Javascript file under the `src` folder excluding `src/lib`.
Expand All @@ -24,12 +28,26 @@ Running `gulp jshint` will lint any Javascript file under the `src` folder exclu

The express server app uses [docstore](https://www.npmjs.com/package/docstore) to store users and ideas in JSON format. If this storage location gets messy, `gulp clean:db` can be used to clear up the datastore.

## Contributing

Before commiting code, make sure
* you run `gulp jshint` to lint the code and solve any issues presented
* change `package.json` and `bower.json` if a new module was installed using the `--save` command line switch, i.e. `[npm|bower] install --save {module_name}`
* Add `package.json` or `bower.json` to a separate commit with a reason to pull that module into the build
* Update the unit tests in the corresponding .spec.js file in the same folder. If one doesn't exist, create a file with the same name as the folder followed by ".spec.js". This marks the file as a unit test file.

**Note**: Do not push to the stable branch, commiting to the stable branch will result in code being lost. The stable branch is created for milestone releases.

## Useful links

[Angular Docs](https://docs.angularjs.org/api)

[Angular Material Docs](https://material.angularjs.org/#/)

[Lodash API](https://lodash.com/docs)

[Jasmine BDD docs](http://jasmine.github.io/2.3/introduction.html)

[List of Material Icons](https://klarsys.github.io/angular-material-icons/)

[Material Design color guide](http://www.google.com/design/spec/style/color.html#)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"angular": "~1.3.15",
"angular-mocks": "~1.3.15",
"angular-animate": "~1.3.15",
"angular-material": "~0.8.3",
"angular-material": "~0.9.4",
"angular-ui-router": "~0.2.13",
"lodash": "~3.8.0",
"moment": "~2.10.2"
Expand Down
29 changes: 20 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,43 @@ var gulp = require('gulp'),
gutil = require('gulp-util'),
os = require('os'),
del = require('del'),
colors = require('colors'),
chalk = require('chalk'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish-ex'),
nodemon = require('gulp-nodemon');
nodemon = require('gulp-nodemon'),
karma = require('karma').server;

gulp.task('default', ['usage']);

gulp.task('usage', function() {
var usageLines = [
'',
'',
colors.green('usage'),
chalk.green('usage'),
'\tDisplay this help page.',
'',
colors.green('start'),
chalk.green('start'),
'\t runs the app server using express.',
'',
colors.green('jshint'),
chalk.green('test:client'),
'\t runs the client side tests using karma.',
'',
chalk.green('jshint'),
'\tRun jshint on the spec and the js folder under src.',
'',
colors.green('clean:modules'),
chalk.green('clean:modules'),
'\tDeletes the npm_modules and the src/lib directories.',
'\t' + colors.magenta('NOTE:') + ' ' + colors.green('npm install') +
'\t' + chalk.magenta('NOTE:') + ' ' + chalk.green('npm install') +
' will be required before running the app.',
'',
colors.green('clean:db'),
chalk.green('clean:db'),
'\tResets the persistent app storage by clearing out the datastore folder.',
''
];
gutil.log(usageLines.join(os.EOL));
});

gulp.task('start', ['_cleanUp'], function() {
gulp.task('start', ['_cleanUp', 'test:client'], function() {
nodemon({
script: 'server/server.js',
'ignore': ['spec/*']
Expand All @@ -50,6 +54,13 @@ gulp.task('jshint', function() {
.pipe(jshint.reporter(stylish));
});

gulp.task('test:client', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});

gulp.task('clean:modules', function() {
return del([
'node_modules',
Expand Down
82 changes: 82 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Karma configuration
// Generated on Mon May 25 2015 16:54:36 GMT+0530 (IST)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
'src/lib/angular/angular.js',
'src/lib/angular-mocks/angular-mocks.js',
'src/lib/angular-ui-router/release/angular-ui-router.js',
'src/lib/angular-animate/angular-animate.js',
'src/lib/angular-aria/angular-aria.js',
'src/lib/angular-material/angular-material.js',
'src/lib/angular-material/angular-material-mocks.js',
'src/lib/moment/moment.js',
'src/lib/lodash/lodash.js',
'src/app.js',
'src/ideas/ideaSvc/ideaSvc.mock.js',
'src/users/loginSvc/loginSvc.mock.js',
'src/homeView/homeView.js',
'src/ideas/**/*.js',
'src/navigation/**/*.js',
'src/users/**/*.js',
'src/**/*.spec.js'
],


// list of files to exclude
exclude: [
'src/assets/**/*'
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"gulp-jshint": "^1.10.0",
"gulp-nodemon": "^2.0.2",
"gulp-util": "^3.0.4",
"jshint-stylish-ex": "^0.2.0"
"jasmine": "^2.3.1",
"jasmine-core": "^2.3.4",
"jshint-stylish-ex": "^0.2.0",
"karma": "^0.12.32",
"karma-cli": "0.0.4",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.1.4"
}
}
34 changes: 30 additions & 4 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ app.post('/login', function(req, res) {
status: 'AUTH_OK',
id: doc.accountId,
username: req.body.username,
name: doc.name
name: doc.name,
likedIdeas: doc.likedIdeas
});
}
else {
Expand All @@ -81,7 +82,8 @@ app.post('/signup', function(req, res) {
_id: req.body.username,
accountId: req.body.id,
password: req.body.password,
name: req.body.name
name: req.body.name,
likedIdeas: req.body.likedIdeas
},
function(err, doc) {
if (err) {
Expand All @@ -103,7 +105,6 @@ app.post('/idea', function(req, res) {
description: req.body.description,
author: req.body.author,
likes: req.body.likes,
managerLikes: req.body.managerLikes,
comments: req.body.comments,
backs: req.body.backs
},
Expand Down Expand Up @@ -136,6 +137,27 @@ app.post('/updateidea', function(req, res) {
}
});
});
app.post('/updateaccount', function(req, res) {
userDb.get(req.body.username, function(err, doc) {
if (err) {
res.sendStatus(500);
}
else {
_.assign(doc, req.body);
doc.status = undefined;
doc.id = undefined;
userDb.save(doc, function(err, doc) {
if (err) {
console.log(chalk.bgRed(err));
}
else {
console.log(chalk.bgGreen('Document with key %s updated in account.'), doc.key);
res.sendStatus(200);
}
});
}
});
});

app.get('/idea', function(req, res) {
ideasDb.get('idea_' + req.query.id, function(err, doc) {
Expand Down Expand Up @@ -207,7 +229,11 @@ app.get('/uniqueid', function(req, res) {

external(function (err, ipExternal) {
if (err) {
throw err;
console.log(
chalk.red('Could not determine network status, server running in local-only mode') +
'\nServer listening at' +
'\n\tlocal: ' + chalk.magenta('http://localhost:8080')
);
}
else {
console.log(
Expand Down
9 changes: 9 additions & 0 deletions src/assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ body {

.top-ideas-list-item {
margin-left: 20px;
}

.custom-chip {
margin-left: 5px;
margin-right: 5px;
padding: 3px 6px;
background-color: #e0e0e0;
color: #424242;
border-radius: 10px;
}
14 changes: 14 additions & 0 deletions src/homeView/homeView.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('HomeViewCtrl', function() {
var scope, ctrl;

beforeEach(module('flintAndSteel'));

beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('HomeViewCtrl', { $scope: scope });
}));

it('should exist', function() {
expect(scope).toBeDefined();
});
});
3 changes: 1 addition & 2 deletions src/ideas/addIdeaView/addIdeaView.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ angular.module('flintAndSteel')

$scope.addNewIdea = function addNewIdea(ideaToAdd) {
ideaToAdd.likes = 0;
ideaToAdd.managerLikes = 0;
ideaToAdd.comments = [];
ideaToAdd.backs = [];
ideaSvc.postIdea($scope.idea, function postIdeaSuccess(data) {
console.log(data);
if (data == 'Created') {
if (data === 'Created') {
$mdToast.show(
$mdToast.simple()
.content('New idea created successfully!')
Expand Down
41 changes: 41 additions & 0 deletions src/ideas/addIdeaView/addIdeaView.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
describe('AddIdeaViewCtrl', function() {
var scope, ctrl, $mdToast, $state, ideaSvcMock;

beforeEach(module('flintAndSteel'));
beforeEach(module('ui.router'));

beforeEach(inject(function($rootScope, $controller, _$mdToast_, _$state_, _ideaSvcMock_) {
scope = $rootScope.$new();
$mdToast = _$mdToast_;
$state = _$state_;
ideaSvcMock = _ideaSvcMock_;

spyOn($state, 'go');
spyOn(ideaSvcMock, 'postIdea');

ctrl = $controller('AddIdeaViewCtrl', {
$scope: scope,
$state: $state,
$mdToast: $mdToast,
ideaSvc: ideaSvcMock
});
}));

it('should exist', function() {
expect(ctrl).toBeDefined();
});

it('should add a new idea', function() {
var idea = {
title: 'Test Title',
author: 'Test',
description: 'This is a test idea.',
};
scope.addNewIdea(idea);

expect(ideaSvcMock.postIdea).toHaveBeenCalled();
expect(idea.likes).toBe(0);
expect(idea.comments.length).toBe(0);
expect(idea.backs.length).toBe(0);
});
});
Loading

0 comments on commit 1a31d5c

Please sign in to comment.