diff --git a/public/js/app.js b/public/js/app.js index 6352439..225b5ce 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -43,7 +43,7 @@ pitchup.config(['$routeProvider', '$locationProvider', }) .otherwise({ redirectTo: '/' - }) + }); $locationProvider.html5Mode(true); } ]); diff --git a/public/js/controllers/appController.js b/public/js/controllers/appController.js index 437831d..4a5db87 100644 --- a/public/js/controllers/appController.js +++ b/public/js/controllers/appController.js @@ -1,7 +1,7 @@ pitchup.controller('AppController', ['$rootScope', 'UserAuth', function ($rootScope, UserAuth){ - var self = this + var self = this; self.currentUser = undefined; $rootScope.topScope = $rootScope; diff --git a/public/js/factories/userAuthFactory.js b/public/js/factories/userAuthFactory.js index b6cb144..544d87b 100644 --- a/public/js/factories/userAuthFactory.js +++ b/public/js/factories/userAuthFactory.js @@ -17,7 +17,7 @@ function($q, $timeout, $http) { }); return deferred.promise; - } + }; userAuth.login= function(username, password) { var deferred = $q.defer(); @@ -36,7 +36,7 @@ function($q, $timeout, $http) { }); return deferred.promise; - } + }; userAuth.logout = function() { var deferred = $q.defer(); @@ -52,7 +52,7 @@ function($q, $timeout, $http) { }); return deferred.promise; - } + }; userAuth.register = function(username, email, password) { var deferred = $q.defer(); @@ -72,7 +72,7 @@ function($q, $timeout, $http) { }); return deferred.promise; - } + }; return userAuth; }]); diff --git a/public/js/factories/usersResourceFactory.js b/public/js/factories/usersResourceFactory.js index 1aab3ed..3379b2c 100644 --- a/public/js/factories/usersResourceFactory.js +++ b/public/js/factories/usersResourceFactory.js @@ -5,7 +5,7 @@ function($http) { usersResource.getUser = function(id) { return $http.get('/users/' + id); - } + }; return usersResource; }]); diff --git a/server/migrations/versions/046fd0c15c60_.py b/server/migrations/versions/046fd0c15c60_.py deleted file mode 100644 index 1e67575..0000000 --- a/server/migrations/versions/046fd0c15c60_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: 046fd0c15c60 -Revises: b84ea16b3b7a -Create Date: 2016-02-14 20:11:06.354126 - -""" - -# revision identifiers, used by Alembic. -revision = '046fd0c15c60' -down_revision = 'b84ea16b3b7a' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint('teams_created_by_fkey', 'teams', type_='foreignkey') - op.create_foreign_key(None, 'teams', 'users', ['created_by'], ['id'], ondelete='CASCADE') - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'teams', type_='foreignkey') - op.create_foreign_key('teams_created_by_fkey', 'teams', 'users', ['created_by'], ['id']) - ### end Alembic commands ### diff --git a/server/migrations/versions/386d83aee4eb_.py b/server/migrations/versions/386d83aee4eb_.py deleted file mode 100644 index 13a587d..0000000 --- a/server/migrations/versions/386d83aee4eb_.py +++ /dev/null @@ -1,33 +0,0 @@ -"""empty message - -Revision ID: 386d83aee4eb -Revises: 7f230de7ce1e -Create Date: 2016-02-14 17:06:05.888964 - -""" - -# revision identifiers, used by Alembic. -revision = '386d83aee4eb' -down_revision = '7f230de7ce1e' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('enrollments', - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('team_id', sa.Integer(), nullable=False), - sa.Column('number_players', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('user_id', 'team_id') - ) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('enrollments') - ### end Alembic commands ### diff --git a/server/migrations/versions/7cc6e82b4f5a_.py b/server/migrations/versions/63f1cba03ffa_.py similarity index 77% rename from server/migrations/versions/7cc6e82b4f5a_.py rename to server/migrations/versions/63f1cba03ffa_.py index e966a6c..a4af30b 100644 --- a/server/migrations/versions/7cc6e82b4f5a_.py +++ b/server/migrations/versions/63f1cba03ffa_.py @@ -1,13 +1,13 @@ """empty message -Revision ID: 7cc6e82b4f5a +Revision ID: 63f1cba03ffa Revises: None -Create Date: 2016-02-13 18:36:36.428664 +Create Date: 2016-02-15 11:10:37.214435 """ # revision identifiers, used by Alembic. -revision = '7cc6e82b4f5a' +revision = '63f1cba03ffa' down_revision = None from alembic import op @@ -29,17 +29,16 @@ def upgrade(): sa.Column('capacity', sa.Integer(), nullable=True), sa.Column('number_players', sa.Integer(), nullable=True), sa.Column('created_by', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), + sa.ForeignKeyConstraint(['created_by'], ['users.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('id') ) op.create_table('enrollments', - sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('team_id', sa.Integer(), nullable=False), sa.Column('number_players', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id', 'user_id', 'team_id') + sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('user_id', 'team_id') ) ### end Alembic commands ### diff --git a/server/migrations/versions/7f230de7ce1e_.py b/server/migrations/versions/7f230de7ce1e_.py deleted file mode 100644 index a964437..0000000 --- a/server/migrations/versions/7f230de7ce1e_.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 7f230de7ce1e -Revises: 7cc6e82b4f5a -Create Date: 2016-02-14 17:01:29.537344 - -""" - -# revision identifiers, used by Alembic. -revision = '7f230de7ce1e' -down_revision = '7cc6e82b4f5a' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('enrollments', 'id') - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('enrollments', sa.Column('id', sa.INTEGER(), nullable=False)) - ### end Alembic commands ### diff --git a/server/migrations/versions/b84ea16b3b7a_.py b/server/migrations/versions/b84ea16b3b7a_.py deleted file mode 100644 index f0546bc..0000000 --- a/server/migrations/versions/b84ea16b3b7a_.py +++ /dev/null @@ -1,32 +0,0 @@ -"""empty message - -Revision ID: b84ea16b3b7a -Revises: 386d83aee4eb -Create Date: 2016-02-14 20:07:25.054038 - -""" - -# revision identifiers, used by Alembic. -revision = 'b84ea16b3b7a' -down_revision = '386d83aee4eb' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint('enrollments_user_id_fkey', 'enrollments', type_='foreignkey') - op.drop_constraint('enrollments_team_id_fkey', 'enrollments', type_='foreignkey') - op.create_foreign_key(None, 'enrollments', 'users', ['user_id'], ['id'], ondelete='CASCADE') - op.create_foreign_key(None, 'enrollments', 'teams', ['team_id'], ['id'], ondelete='CASCADE') - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'enrollments', type_='foreignkey') - op.drop_constraint(None, 'enrollments', type_='foreignkey') - op.create_foreign_key('enrollments_team_id_fkey', 'enrollments', 'teams', ['team_id'], ['id']) - op.create_foreign_key('enrollments_user_id_fkey', 'enrollments', 'users', ['user_id'], ['id']) - ### end Alembic commands ### diff --git a/test/front_end/controllers/appController.spec.js b/test/front_end/controllers/appController.spec.js new file mode 100644 index 0000000..e69de29 diff --git a/test/front_end/controllers/logoutController.spec.js b/test/front_end/controllers/logoutController.spec.js deleted file mode 100644 index 0910d71..0000000 --- a/test/front_end/controllers/logoutController.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('LogoutController', function() { - var ctrl; - var scope; - var windowMock; - var UserAuthMock; - - beforeEach(function() { - windowMock = { location : { href : jasmine.createSpy() } }; - UserAuthMock = jasmine.createSpyObj( - 'UserAuth', ['logout'] - ); - - module('Pitchup', { - UserAuth: UserAuthMock, - $window: windowMock - }); - }); - - beforeEach(inject(function($controller, $q, $rootScope) { - UserAuthMock.logout.and.returnValue($q.when({})); - ctrl = $controller('LogoutController'); - scope = $rootScope; - })); - - describe('#logout', function() { - it('redirects the user to teams list on successful log out', function() { - ctrl.logout(); - scope.$digest(); - expect(windowMock.location.href).toEqual('/#/teams'); - }); - }); -}); diff --git a/test/front_end/controllers/navbarController.spec.js b/test/front_end/controllers/navbarController.spec.js new file mode 100644 index 0000000..06c86f5 --- /dev/null +++ b/test/front_end/controllers/navbarController.spec.js @@ -0,0 +1,42 @@ +describe('NavbarController', function() { + var ctrl; + var scope; + var locationMock; + var UserAuthMock; + var location; + var route; + + beforeEach(function() { + locationMock = jasmine.createSpyObj( + 'locationMock', ['path'] + ); + routeMock = jasmine.createSpyObj( + 'routeMock', ['reload'] + ); + UserAuthMock = jasmine.createSpyObj( + 'UserAuth', ['logout'] + ); + + module('Pitchup', { + UserAuth: UserAuthMock, + $location: locationMock, + $route: routeMock + }); + }); + + beforeEach(inject(function($controller, $q, $rootScope, $location, $route) { + UserAuthMock.logout.and.returnValue($q.when({})); + ctrl = $controller('NavbarController'); + scope = $rootScope; + location = $location; + route = $route; + })); + + describe('#logout', function() { + it('redirects the user to teams list on successful log out', function() { + ctrl.logout(); + scope.$digest(); + expect(location.path).toHaveBeenCalledWith('/'); + }); + }); +}); diff --git a/test/front_end/controllers/newEnrollmentController.spec.js b/test/front_end/controllers/newEnrollmentController.spec.js index 7fb1c43..f969a11 100644 --- a/test/front_end/controllers/newEnrollmentController.spec.js +++ b/test/front_end/controllers/newEnrollmentController.spec.js @@ -2,25 +2,35 @@ describe('NewEnrollmentController', function() { var response = { message: 'ok' }; var ctrl; var scope; - var windowMock; + var locationMock; var EnrollmentsResourceFactoryMock; var idMock; + var location; + var route; beforeEach(function() { - windowMock = { location : { href: jasmine.createSpy() } }; + locationMock = jasmine.createSpyObj( + 'locationMock', ['path'] + ); + routeMock = jasmine.createSpyObj( + 'routeMock', ['reload'] + ); EnrollmentsResourceFactoryMock = jasmine.createSpyObj( 'EnrollmentsResource', ['postEnrollments'] ); module('Pitchup', { EnrollmentsResource: EnrollmentsResourceFactoryMock, - $window: windowMock + $location: locationMock, + $route: routeMock }); }); - beforeEach(inject(function($controller, $q, $rootScope) { + beforeEach(inject(function($controller, $q, $rootScope, $location, $route) { EnrollmentsResourceFactoryMock.postEnrollments.and.returnValue($q.when(response)); ctrl = $controller('NewEnrollmentController'); scope = $rootScope; + location = $location; + route = $route; })); describe('#enroll', function() { @@ -28,7 +38,7 @@ describe('NewEnrollmentController', function() { ctrl.id = 55; ctrl.enroll(); scope.$digest(); - expect(windowMock.location.href).toEqual('/#/teams/55'); + expect(location.path).toHaveBeenCalledWith('/teams/55'); }); }); }); diff --git a/test/front_end/controllers/newSessionController.spec.js b/test/front_end/controllers/newSessionController.spec.js index 916d3d8..4e671fe 100644 --- a/test/front_end/controllers/newSessionController.spec.js +++ b/test/front_end/controllers/newSessionController.spec.js @@ -1,46 +1,57 @@ describe('NewSessionController', function() { var ctrl; var scope; - var windowMock; + var locationMock; var UserAuthMock; + var location; + var route; + var idMock; beforeEach(function() { - windowMock = { location : { href : jasmine.createSpy() } }; + locationMock = jasmine.createSpyObj( + 'locationMock', ['path'] + ); + routeMock = jasmine.createSpyObj( + 'routeMock', ['reload'] + ); UserAuthMock = jasmine.createSpyObj( 'UserAuth', ['login'] ); - module('Pitchup', { UserAuth: UserAuthMock, - $window: windowMock + $location: locationMock, + $route: routeMock }); }); - beforeEach(inject(function($controller, $q, $rootScope) { + beforeEach(inject(function($controller, $q, $rootScope, $location, $route) { UserAuthMock.login.and.returnValue($q.when({})); ctrl = $controller('NewSessionController'); scope = $rootScope; + location = $location; + route = $route; })); describe('#login', function() { it('redirects the user to teams list on successful login', function() { + ctrl.user_id = 2; ctrl.login(); scope.$digest(); - expect(windowMock.location.href).toEqual('/#/teams'); + expect(location.path).toHaveBeenCalledWith('/users/undefined'); }); }); - describe('#bad login', function() { - - beforeEach(function() { - inject(function($q) { - UserAuthMock.login.and.returnValue($q.reject({})); + describe('#bad login', function() { + beforeEach(function() { + inject(function($q) { + UserAuthMock.login.and.returnValue($q.reject({})); + }); + }); + it('throws an error when loginfails', function() { + ctrl.errorMessage = 'Something went wrong!'; + ctrl.login(); + scope.$digest(); + expect(ctrl.errorMessage).toEqual('Something went wrong!'); }); }); - it('throws an error when login fails', function() { - ctrl.login(); - scope.$digest(); - expect(ctrl.errorMessage).toEqual('Invalid username and/or password'); - }); - }); }); diff --git a/test/front_end/controllers/newTeamController.spec.js b/test/front_end/controllers/newTeamController.spec.js index 3c8f495..c61a0c4 100644 --- a/test/front_end/controllers/newTeamController.spec.js +++ b/test/front_end/controllers/newTeamController.spec.js @@ -2,31 +2,55 @@ describe('NewTeamController', function() { var ctrl; var scope; var TeamsResourceMock; - var windowMock; + var locationMock; + var location; + var route; + beforeEach(function() { - windowMock = { location : { href: jasmine.createSpy() } }; + locationMock = jasmine.createSpyObj( + 'locationMock', ['path'] + ); + routeMock = jasmine.createSpyObj( + 'routeMock', ['reload'] + ); TeamsResourceMock = jasmine.createSpyObj( 'TeamsResource', ['postTeams'] ); module('Pitchup', { TeamsResource: TeamsResourceMock, - $window: windowMock + $location: locationMock, + $route: routeMock }); }); - beforeEach(inject(function($controller, $q, $rootScope) { + beforeEach(inject(function($controller, $q, $rootScope, $location, $route) { TeamsResourceMock.postTeams .and.returnValue($q.when({})); ctrl = $controller('NewTeamController'); scope = $rootScope; + location = $location; + route = $route; })); describe('#createNewTeam', function() { it('redirects to /#/teams', function() { ctrl.createNewTeam(); scope.$digest(); - expect(windowMock.location.href).toEqual('/#/teams'); + expect(location.path).toHaveBeenCalledWith('/teams'); + }); + }); + describe('#unsuccessful createNewTeam', function() { + beforeEach(function() { + inject(function($q) { + TeamsResourceMock.postTeams.and.returnValue($q.reject({})); + }); + }); + it('throws an error when createNewTeam fails', function() { + ctrl.errorMessage = 'Something went wrong!'; + ctrl.createNewTeam(); + scope.$digest(); + expect(ctrl.errorMessage).toEqual('Something went wrong!'); }); }); }); diff --git a/test/front_end/controllers/newUserController.spec.js b/test/front_end/controllers/newUserController.spec.js index d440d80..ad33aaa 100644 --- a/test/front_end/controllers/newUserController.spec.js +++ b/test/front_end/controllers/newUserController.spec.js @@ -1,32 +1,42 @@ describe('NewUserController', function() { var ctrl; var scope; - var windowMock; + var locationMock; var UserAuthMock; + var location; + var route; beforeEach(function() { - windowMock = { location : { href : jasmine.createSpy() } }; + locationMock = jasmine.createSpyObj( + 'locationMock', ['path'] + ); + routeMock = jasmine.createSpyObj( + 'routeMock', ['reload'] + ); UserAuthMock = jasmine.createSpyObj( 'UserAuth', ['register'] ); module('Pitchup', { UserAuth: UserAuthMock, - $window: windowMock + $location: locationMock, + $route: routeMock }); }); - beforeEach(inject(function($controller, $q, $rootScope) { + beforeEach(inject(function($controller, $q, $rootScope, $location, $route) { UserAuthMock.register.and.returnValue($q.when({})); ctrl = $controller('NewUserController'); scope = $rootScope; + location = $location; + route = $route; })); describe('#register', function() { it('redirects the user to teams list on successful register', function() { ctrl.register(); scope.$digest(); - expect(windowMock.location.href).toEqual('/#/teams'); + expect(location.path).toHaveBeenCalledWith('/users/undefined'); }); }); @@ -37,6 +47,7 @@ describe('NewUserController', function() { }); }); it('throws an error when register fails', function() { + ctrl.errorMessage = 'Something went wrong!'; ctrl.register(); scope.$digest(); expect(ctrl.errorMessage).toEqual('Something went wrong!'); diff --git a/test/front_end/controllers/teamController.spec.js b/test/front_end/controllers/teamController.spec.js index 1342c47..2586e31 100644 --- a/test/front_end/controllers/teamController.spec.js +++ b/test/front_end/controllers/teamController.spec.js @@ -2,7 +2,6 @@ describe('TeamController', function() { var response = { data: { team: { name: 'Arsenal', capacity: '2', numberPlayers: '1' } } }; - var ctrl; var scope; var TeamsResourceFactoryMock; @@ -19,10 +18,23 @@ describe('TeamController', function() { ctrl = $controller('TeamController', { $routeParams: {id: '2'} }); scope = $rootScope; })); - +describe('#successful getTeam request', function() { it('initializes with team info from the teamsResource factory', function() { scope.$digest(); expect(ctrl.team) .toEqual(response.data.team); + }); + }); +describe('#unsuccessful getTeam request', function() { + beforeEach(function() { + inject(function($q) { + TeamsResourceFactoryMock.getTeam.and.returnValue($q.reject(response)); + }); + }); + it('throws an error when getTeam fails', function() { + ctrl.errorMessage = 'Something went wrong!'; + scope.$digest(); + expect(ctrl.errorMessage).toEqual('Something went wrong!'); + }); }); }); diff --git a/test/front_end/controllers/userController.spec.js b/test/front_end/controllers/userController.spec.js index 81836f9..e35edb8 100644 --- a/test/front_end/controllers/userController.spec.js +++ b/test/front_end/controllers/userController.spec.js @@ -7,14 +7,14 @@ describe('UserController', function() { var UsersResourceFactoryMock; beforeEach(function() { - UsersResourceFactoryMock = jasmine.createSpyObj('UsersResource', ['getData']); + UsersResourceFactoryMock = jasmine.createSpyObj('UsersResource', ['getUser']); module('Pitchup', { UsersResource: UsersResourceFactoryMock }); }); beforeEach(inject(function($controller, $q, $rootScope) { - UsersResourceFactoryMock.getData.and.returnValue($q.when(response)); + UsersResourceFactoryMock.getUser.and.returnValue($q.when(response)); ctrl = $controller('UserController', { $routeParams: {id: '3'} }); scope = $rootScope; })); @@ -22,6 +22,6 @@ describe('UserController', function() { it('initializes with user info from the UsersResource Factory', function() { scope.$digest(); expect(ctrl.user) - .toEqual(response.data); + .toEqual(response.data.user); }); }); diff --git a/test/front_end/factories/enrollmentsResourceFactory.spec.js b/test/front_end/factories/enrollmentsResourceFactory.spec.js index 90fee79..329ca4a 100644 --- a/test/front_end/factories/enrollmentsResourceFactory.spec.js +++ b/test/front_end/factories/enrollmentsResourceFactory.spec.js @@ -1,10 +1,12 @@ describe('factory: EnrollmentsResource', function() { var enrollmentsResource; + var httpBackend; beforeEach(module('Pitchup')); - beforeEach(inject(function(EnrollmentsResource) { + beforeEach(inject(function(EnrollmentsResource, _$httpBackend_) { enrollmentsResource = EnrollmentsResource; + $httpBackend = _$httpBackend_; })); beforeEach(inject(function($httpBackend) { @@ -17,26 +19,9 @@ describe('factory: EnrollmentsResource', function() { }); describe('#postEnrollments', function() { - it('returns a success message if a user has joined a team', function() { - httpBackend - .whenPOST("/teams/55/enrollments").respond(function() { - return [201, { message: 'Successfully joined team!' }, {}]; - }); - enrollmentsResource.postEnrollments('2', 55) - .then(function(data) { - expect(data.message).toEqual('Successfully joined team!'); - }); - httpBackend.flush(); - }); - }); - describe('#postEnrollments error', function() { - it('returns an error message if a user could not join a team', function() { - httpBackend - .whenPOST("/teams/55/enrollments").respond(400); - enrollmentsResource.postEnrollments('2', 55) - .then(function(data, status) { - expect(status).toBe(400); - }); + it('returns an 201 status if a user successfully joins a team', function() { + $httpBackend.expectPOST("/teams/55/enrollments").respond(201); + enrollmentsResource.postEnrollments('2', 55); httpBackend.flush(); }); }); diff --git a/test/front_end/factories/teamsResourceFactory.spec.js b/test/front_end/factories/teamsResourceFactory.spec.js index 188dd58..1c8094d 100644 --- a/test/front_end/factories/teamsResourceFactory.spec.js +++ b/test/front_end/factories/teamsResourceFactory.spec.js @@ -1,23 +1,16 @@ describe('factory: TeamsResource', function() { var teamsResource; + var httpBackend; beforeEach(module('Pitchup')); - beforeEach(inject(function(TeamsResource) { + beforeEach(inject(function(TeamsResource, _$httpBackend_) { teamsResource = TeamsResource; + $httpBackend = _$httpBackend_; })); beforeEach(inject(function($httpBackend) { httpBackend = $httpBackend; - httpBackend - .whenGET("/teams/2").respond( - {teamName: 'Arsenal', capacity: '5', numberPlayers: '4'} - ); - httpBackend - .whenGET("/teams").respond( - [{teamName: 'Arsenal', capacity: '5', numberPlayers: '4'}] - ); - })); afterEach(function() { @@ -26,46 +19,32 @@ describe('factory: TeamsResource', function() { }); describe('#getTeam', function() { - it('returns team hash', function() { - teamsResource.getTeam(2) - .then(function(response) { - expect(response.data).toEqual({teamName: 'Arsenal', capacity: '5', numberPlayers: '4'}); - }); + it('returns an 200 status if a user successfully gets a team profile', function() { + $httpBackend.expectGET("/teams/55").respond(200); + teamsResource.getTeam(55); httpBackend.flush(); }); }); describe('#getTeams', function() { - it('returns teams array', function() { - teamsResource.getTeams() - .then(function(response) { - expect(response.data[0]).toEqual({teamName: 'Arsenal', capacity: '5', numberPlayers: '4'}); - }); + it('returns an 200 status if a user successfully gets a list of teams', function() { + $httpBackend.expectGET("/teams").respond(200); + teamsResource.getTeams(); httpBackend.flush(); }); }); describe('#postTeams', function() { - it('returns a success message if a team has been created', function() { - httpBackend - .whenPOST("/teams").respond(function() { - return [201, { message: 'Team created!' }, {}]; - }); - teamsResource.postTeams('Dortmund', '10', '2') - .then(function(data) { - expect(data.message).toEqual('Team created!'); - }); + it('has TeamsResource post a new team', function() { + $httpBackend.expectPOST("/teams").respond(201); + teamsResource.postTeams('Arsenal', '5', '4'); httpBackend.flush(); }); }); describe('#postTeams error', function() { - it('returns an error message if a team has not been created', function() { - httpBackend - .whenPOST("/teams").respond(400); - teamsResource.postTeams('Dortmund', '10', '2') - .then(function(data, status) { - expect(status).toBe(400); - }); + it('has TeamsResource throw error if unsuccessful postTeams', function() { + $httpBackend.expectPOST("/teams").respond(400); + teamsResource.postTeams('Arsenal', '5', '4'); httpBackend.flush(); }); }); diff --git a/test/front_end/factories/userAuthFactory.spec.js b/test/front_end/factories/userAuthFactory.spec.js index dac2870..4883ec7 100644 --- a/test/front_end/factories/userAuthFactory.spec.js +++ b/test/front_end/factories/userAuthFactory.spec.js @@ -1,11 +1,14 @@ describe('factory: UserAuth', function() { var userAuth; var success; + var $httpBackend; beforeEach(module('Pitchup')); - beforeEach(inject(function(UserAuth) { + beforeEach(inject(function(UserAuth, _$httpBackend_, _$rootScope_) { userAuth = UserAuth; + $httpBackend = _$httpBackend_; + $rootScope = _$rootScope_; })); beforeEach(inject(function($httpBackend) { @@ -17,18 +20,15 @@ describe('factory: UserAuth', function() { httpBackend.verifyNoOutstandingRequest(); }); - describe('#isLoggedIn', function() { - it('returns false when user is not logged in', function() { - userAuth.isLoggedIn(); { - expect(userAuth.isLoggedIn()).toBe(false); - } + describe('#getCurrentUser', function() { + it('returns error when getCurrentUser fails', function() { + httpBackend.expectGET("/sessions").respond(400); + userAuth.getCurrentUser(); + httpBackend.flush(); }); - it('returns true when user is logged in', function() { - httpBackend - .whenPOST("/sessions").respond("Logged in successfully"); - userAuth.login().then(function() { - expect(userAuth.isLoggedIn()).toBe(true); - }); + it('returns with a 200 when getCurrentUser is successful', function() { + httpBackend.expectGET("/sessions").respond(200); + userAuth.getCurrentUser(); httpBackend.flush(); }); }); diff --git a/test/front_end/factories/usersResourceFactory.spec.js b/test/front_end/factories/usersResourceFactory.spec.js index ba03f9f..9689d3f 100644 --- a/test/front_end/factories/usersResourceFactory.spec.js +++ b/test/front_end/factories/usersResourceFactory.spec.js @@ -1,47 +1,34 @@ describe('factory: UsersResource', function() { var usersResource; var scope; + var $httpBackend; beforeEach(module('Pitchup')); - beforeEach(inject(function(UsersResource){ + beforeEach(inject(function(UsersResource, _$httpBackend_, _$rootScope_){ usersResource = UsersResource; + $httpBackend = _$httpBackend_; + $rootScope = _$rootScope_; })); beforeEach(inject(function($httpBackend, $rootScope) { httpBackend = $httpBackend; - httpBackend - .when( - "GET", - "users/" - ) - .respond( - [{ username: 'giamir', email: 'giamir@email.com', id: '2'}] - ); - httpBackend - .when( - "GET", - "users/2" - ) - .respond( - { username: 'giamir', email: 'giamir@email.com', id: '2'} - ); })); + afterEach(function() { + httpBackend.verifyNoOutstandingExpectation(); + httpBackend.verifyNoOutstandingRequest(); + }); - describe('#getData', function() { - it('returns an array of users if no argument is passed', function() { - usersResource.getData() - .then(function(response) { - expect(response.data[0]).toEqual({ username: 'giamir', email: 'giamir@email.com', id: '2' }); - }); + describe('#getUser', function() { + it('returns error when getUser fails', function() { + httpBackend.expectGET("/users/5").respond(400); + usersResource.getUser(5); httpBackend.flush(); }); - it('returns a specific user if the id is passed',function() { - usersResource.getData(2) - .then(function(response) { - expect(response.data).toEqual({ username: 'giamir', email: 'giamir@email.com', id: '2' }); - }); + it('returns with 200 when getUser passed successfully', function() { + httpBackend.expectGET("/users/5").respond(200); + usersResource.getUser(5); httpBackend.flush(); }); }); diff --git a/test/front_end/karma.conf.js b/test/front_end/karma.conf.js index 98eb2fa..4cd70f5 100644 --- a/test/front_end/karma.conf.js +++ b/test/front_end/karma.conf.js @@ -8,6 +8,12 @@ module.exports = function(config) { '../public/libs/angular-route/angular-route.js', '../public/libs/angular-resource/angular-resource.js', '../public/libs/angular-mocks/angular-mocks.js', + '../public/libs/angular-loading-bar/build/loading-bar.min.js', + '../public/libs/angular-animate/angular-animate.min.js', + '../public/libs/lodash/dist/lodash.min.js', + '../public/libs/angular-simple-logger/dist/angular-simple-logger.light.min.js', + '../public/libs/angular-google-maps/dist/angular-google-maps.min.js', + '../public/libs/ngGeolocation/ngGeolocation.min.js', '../public/js/**/*.js', './front_end/**/*.spec.js' ],