diff --git a/frontend/cypress/integration/FR5_spec.js b/frontend/cypress/integration/FR5_spec.js index 4105ae15f24e2c4b9d0cd4d686513bbf2ac3586f..594a526be6c26c5203eed21a5eb2be1c10a27c49 100644 --- a/frontend/cypress/integration/FR5_spec.js +++ b/frontend/cypress/integration/FR5_spec.js @@ -1,20 +1,12 @@ /** - * The user should be able to view all of the details, files, and comments - * on workouts of sufficient visibility. - * For athletes, this means that the workout needs to be either their own or public. - * For coaches, this means that the workout is at least one - * of their athletes' non-private workouts OR the workout is public. - * For visitors, this means that the workout needs to be public. + * Helper function for logging in. */ - Cypress.Commands.add('login', (username, password) => { cy.visit('/login.html') cy.get('input[name="username"]').type(username) cy.get('input[name="password"]').type(password) cy.get('#btn-login').click() cy.url().should('contain', '/workouts.html') - cy.intercept('/api/workouts/*').as('getWorkouts') - cy.wait('@getWorkouts') }) Cypress.Commands.add('logout', () => { @@ -24,19 +16,19 @@ Cypress.Commands.add('logout', () => { describe('Testing group functionality and fitness profile', () => { beforeEach(() => { - // Two use profiles with below info are needed to run tests. + // Two user profiles with below info are needed to run tests. // athlete needs to have user "coach" as coach. cy.login('athlete', 'secure') // cy.login('coach', 'secure') + // Adding test data + // three workouts with same owner but different visibility cy.get('#btn-create-workout').click() cy.get('input[name="name"]').type("My public workout") cy.get('input[name="date"]').type('2017-06-01T08:30') cy.get('textarea[name="notes"]').type('This is a note') cy.get('#inputVisibility').select('Public') cy.get('#btn-ok-workout').click() - cy.intercept('/api/workouts/').as('getWorkouts') - cy.wait('@getWorkouts') cy.get('#btn-create-workout').click() cy.get('input[name="name"]').type("My private workout") @@ -44,8 +36,6 @@ describe('Testing group functionality and fitness profile', () => { cy.get('textarea[name="notes"]').type('This is a note') cy.get('#inputVisibility').select('Private') cy.get('#btn-ok-workout').click() - cy.intercept('/api/workouts/').as('getWorkouts') - cy.wait('@getWorkouts') cy.get('#btn-create-workout').click() cy.get('input[name="name"]').type("My coach workout") @@ -53,34 +43,17 @@ describe('Testing group functionality and fitness profile', () => { cy.get('textarea[name="notes"]').type('This is a note') cy.get('#inputVisibility').select('Coach') cy.get('#btn-ok-workout').click() - cy.intercept('/api/workouts/').as('getWorkouts') - cy.wait('@getWorkouts') - - - }) - afterEach(() => { - /* - cy.visit('/workouts.html') - cy.contains('My public workout').click() - cy.get('#btn-edit-workout').click() - cy.get('#btn-delete-workout').click() - cy.contains('My private workout').click() - cy.get('#btn-edit-workout').click() - cy.get('#btn-delete-workout').click() - cy.contains('My coach workout').click() - cy.get('#btn-edit-workout').click() - cy.get('#btn-delete-workout').click() - */ - cy.logout() }) - - it('Testing visibility', () => { + /** + * This test fails because the visibility does not workas intended. + */ + it('Testing visibility as owner, coach, user, and guest', () => { // testing visibility as owner cy.contains('My public workout') - //cy.contains('My coach workout') - //cy.contains('My private workout') + cy.contains('My coach workout') + cy.contains('My private workout') // testing visibility as coach cy.logout() @@ -96,8 +69,6 @@ describe('Testing group functionality and fitness profile', () => { // testing visibility as visitor cy.logout() cy.visit('workouts.html') - cy.intercept('/api/workouts/*').as('getWorkouts') - cy.wait('@getWorkouts') - //cy.contains('My public workout') + cy.contains('My public workout') }) }) \ No newline at end of file diff --git a/frontend/cypress/integration/edit_exercise_spec.js b/frontend/cypress/integration/edit_exercise_spec.js index 0a7e0dd1fb76b927db88f85131a61ccf2ed77beb..24102d3b76cb4dcd9d4223d9228d4c17ffded3f5 100644 --- a/frontend/cypress/integration/edit_exercise_spec.js +++ b/frontend/cypress/integration/edit_exercise_spec.js @@ -1,21 +1,29 @@ +/** + * Helper function to login as a user and receive tokens and + * necesarry authentication. + */ Cypress.Commands.add('login', (username, password) => { cy.visit('/login.html') cy.get('input[name="username"]').type(username) cy.get('input[name="password"]').type(password) + cy.intercept({method: 'POST', url:'/api/token/'}).as('postToken') cy.get('#btn-login').click() - cy.url().should('contain', '/workouts.html') + cy.wait('@postToken').its('response.statusCode').should('eq', 200) +}) + +Cypress.Commands.add('edit', (code) => { + cy.intercept({method: 'PUT', url:'/api/exercises/*'}).as('putExercise') + cy.get('#btn-ok-exercise').click() + cy.wait('@putExercise').its('response.statusCode').should('eq', code) }) describe('Testing boundary value on view/edit exercise page', () => { beforeEach(() => { - //wait for browser to store tokens. - cy.intercept('/api/workouts/*').as('getWorkouts') - cy.login('testuser', 'secure') - cy.wait('@getWorkouts') - // wait for the exercise to be rertrieved from backend. + cy.login('user', 'secure') + // Wait for the view/edit page to load cy.visit('/exercise.html?id=1') cy.intercept('/api/exercises/*').as('getExercises') - cy.wait('@getExercises') + cy.wait('@getExercises').its('response.statusCode').should('eq', 200) // enable editing cy.get('#btn-edit-exercise').click() }) @@ -31,46 +39,82 @@ describe('Testing boundary value on view/edit exercise page', () => { // testing for 51 cy.get('input[name="unit"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') - cy.get('#btn-ok-exercise').click() + cy.edit(400) + cy.get('@putExercise').then((interception) => { + assert.equal(interception.response.body.unit, 'Ensure this field has no more than 50 characters.') + }) cy.contains('Ensure this field has no more than 50 characters.') // testing for 50 cy.get('input[name="unit"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') - cy.get('#btn-ok-exercise').click() - // if valid input then edit button should appear again after clickin the OK button - cy.wait('@getExercises') - cy.get('#btn-edit-exercise').should('be.visible') + cy.edit(200) + cy.get('input[name="unit"]').should('have.value', 'Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') + }) it('Testing lower boundaries for input length for Unit', () => { // testing for 0 cy.get('input[name="unit"]').clear() - cy.get('#btn-ok-exercise').click() + cy.edit(400) + cy.get('@putExercise').then((interception) => { + assert.equal(interception.response.body.unit, 'This field may not be blank.') + }) cy.contains('This field may not be blank.') // testing for 1 - cy.get('input[name="unit"]').clear().type('1') - cy.get('#btn-ok-exercise').click() - // if valid input then edit button should appear again after clickin the OK button - cy.get('#btn-edit-exercise').should('be.visible') + cy.get('input[name="unit"]').clear().type('Y') + cy.edit(200) + cy.get('input[name="unit"]').should('have.value', 'Y') }) /** * The lower boundaries on duration and calories are not enforced and * therefore the tests will fail. - * The tests are testing that the user should be shown a front end validation message. + * It is possible to test for upper boundaries as well, but the tests will + * fail because they are not enforced. */ - it('Testing lower boundaries for duration and calories', () => { + it('Testing lower boundaries for duration', () => { + // Testing frontend HTML form validation lower boundaries cy.get('input[name="duration"]').clear().type('-1').then(($input) => { expect($input[0].validationMessage).to.equal('[Error message]') }) cy.get('input[name="duration"]').clear().type('0').then(($input) => { expect($input[0].validationMessage).to.equal('') }) + + // Testing boundaries backend + // testing for -1 + cy.get('input[name="duration"]').clear().type('-1') + cy.edit(400) + cy.get('@putExercise').then((interception) => { + assert.equal(interception.response.body.duration, '[Error message]') + }) + cy.contains('[Error message]') + // testing for 0 + cy.get('input[name="duration"]').clear().type('0') + cy.edit(200) + cy.get('input[name="duration"]').should('have.value', '0') + + }) + it('Testing lower boundaries for calories', () => { + // Testing frontend HTML form validation lower boundaries cy.get('input[name="calories"]').clear().type('-1').then(($input) => { expect($input[0].validationMessage).to.equal('[Error message]') }) cy.get('input[name="calories"]').clear().type('0').then(($input) => { expect($input[0].validationMessage).to.equal('') }) + // Testing boundaries backend + // testing for -1 + cy.get('input[name="calories"]').clear().type('-1') + cy.edit(400) + cy.get('@putExercise').then((interception) => { + assert.equal(interception.response.body.calories, '[Error message]') + }) + cy.contains('[Error message]') + // testing for 0 + cy.get('input[name="calories"]').clear().type('0') + cy.edit(200) + cy.get('input[name="calories"]').should('have.value', '0') }) + }) \ No newline at end of file diff --git a/frontend/cypress/integration/integration_test_spec.js b/frontend/cypress/integration/integration_test_spec.js index eb6b51c5e2244bf56a719a249b7d56651ac8cf7e..9a268a9aa0c703218061d68ca4a41e66464692a5 100644 --- a/frontend/cypress/integration/integration_test_spec.js +++ b/frontend/cypress/integration/integration_test_spec.js @@ -2,41 +2,47 @@ Cypress.Commands.add('login', (username, password) => { cy.visit('/login.html') cy.get('input[name="username"]').type(username) cy.get('input[name="password"]').type(password) + cy.intercept({method: 'POST', url:'/api/token/'}).as('postToken') cy.get('#btn-login').click() - cy.url().should('contain', '/workouts.html') - cy.intercept('/api/workouts/*').as('getWorkouts') - cy.wait('@getWorkouts') + cy.wait('@postToken').its('response.statusCode').should('eq', 200) }) describe('Testing group functionality and fitness profile', () => { beforeEach(() => { - cy.login('testuser', 'secure') + cy.login('user', 'secure') // wait for the exercise to be rertrieved from backend. cy.visit('/groups.html') cy.intercept('/api/groups/').as('getGroups') cy.wait('@getGroups') }) - it('Testing creating new group', () => { + it('FR29: Testing creating new group', () => { cy.get('#btn-create-group').click() cy.url().should('contain', '/group.html') // typing data for new group cy.get('input[name="name"]').type('My Group') cy.get('textarea[name="description"]').type('This is my group') + cy.intercept({method: 'POST', url:'/api/groups/'}).as('postGroup') cy.get('#btn-ok-group').click() - // waiting for response from backend and checking if group was created. + cy.wait('@postGroup').its('response.statusCode').should('eq', 201) + + // if response ok, then we should be redirected to the groups page. cy.url().should('contain', '/groups.html') cy.intercept('/api/groups/').as('getGroups') - cy.wait('@getGroups') + // intercepting the get request and checking that the new group is + // among the elements we retrieve. + cy.wait('@getGroups').then((interception) => { + assert.equal(interception.response.body.name, 'My Group') + }) + // checking that our group is rendered in the groups list. cy.contains('My Group') cy.contains('This is my group') }) - it('Testing editing group', () => { + it('FR30: Testing editing group', () => { // Finding the group to edit and clicking on it - cy.url().should('contain', '/groups.html') cy.contains('My Group').click() cy.url().should('include', '/groupContent.html?id=') @@ -50,58 +56,90 @@ describe('Testing group functionality and fitness profile', () => { cy.get('#btn-edit-group').click() cy.get('input[name="name"]').clear().type('My Group (edited)') cy.get('textarea[name="description"]').clear().type('This is my group (edited)') - // confirming the edit and checking that i is updated + cy.intercept({method: 'PUT', url:'/api/groups/*'}).as('putGroup') cy.get('#btn-ok-group').click() + cy.wait('@putGroup').its('response.statusCode').should('eq', 200) + + // Check that the edited group appears cy.visit('/groups.html') - cy.wait('@getGroups') cy.contains('My Group (edited)') cy.contains('This is my group (edited)') }) - it('Testing adding content to group', () => { + it('FR31: Testing inviting users', () => { + // Finding the group to to invite users to + cy.contains('My Group').click() + cy.get('#btn-edit-group').click() + + // Inviting user with ID one and expecting response OK + cy.get('input[name="userId"]').clear().type('1') + cy.intercept({method: 'POST', url:'/api/members/'}).as('postMember') + cy.get('#btn-invite-group').click() + cy.wait('@postMember').its('response.statusCode').should('eq', 201) + + // Inviting same meber again should result in error. + cy.get('#btn-invite-group').click() + cy.wait('@postMember').its('response.statusCode').should('eq', 400) + cy.get('@postMember').then((interception) => { + assert.equal(interception.response.body.non_field_errors, 'The fields member, group must make a unique set.') + }) + }) + + it('FR32: Testing adding content to group', () => { cy.contains('My Group (edited)').click() - cy.url().should('include', '/groupContent.html?id=') + // adding input for the group content cy.get('#btn-add-content').click() - cy.get('input[name="title"]').type('My Content') - cy.get('textarea[name="description"]').type('This is content description') + cy.get('input[name="title"]').clear().type('My Content') + cy.get('textarea[name="description"]').clear().type('This is content description') - // typing data for new group + // Adding content and checking that the request is accepted. + cy.intercept({method: 'POST', url:'/api/content/'}).as('postContent') cy.get('#btn-ok-addcontent').click() + cy.wait('@postContent').its('response.statusCode').should('eq', 201) cy.url().should('contain', '/groupContent.html?id=') cy.intercept('/api/content/*').as('getContent') - cy.wait('@getContent') + // intercepting the request and checking that it includes the new content + cy.wait('@getContent').then((interception) => { + assert.equal(interception.response.body.results[0].title, 'My Content') + }) + // checking that the new content is displayed on the page cy.contains('My Content') cy.contains('This is content description') }) - it('Testing adding comments and liking group content', () => { + it('FR33: Testing adding comments and liking group content', () => { // finding the right group and content to post a comment to. cy.contains('My Group (edited)').click() - cy.intercept('/api/content/*').as('getContent') - cy.wait('@getContent') cy.contains('My Content').click() cy.url().should('include', '/contentcomments.html?id=') // typing and adding a comment cy.get('textarea[name="comment"]').type('This is a comment') + cy.intercept({method: 'POST', url:'/api/comment/'}).as('postComment') cy.get('#btn-add-comment').click() + cy.wait('@postComment').its('response.statusCode').should('eq', 201) + cy.intercept('/api/comment/*').as('getComments') + // check if comment was retrieved from backend cy.wait('@getComments').then((interception) => { - assert.isNotNull(interception.response.body, 'API call has data') + assert.equal(interception.response.body.results[0].message, 'This is a comment') }) // check if comment was added cy.contains('This is a comment') - /* // liking content + cy.intercept('/api/like/').as('like') cy.get('#btn-like').click() + cy.wait('@like') + + // liking again should not work cy.intercept('/api/like/').as('like') - cy.wait('@like').its('response.statusCode').should('eq', 200) - */ + cy.get('#btn-like').click() + cy.wait('@like').its('response.statusCode').should('eq', 500) }) - it('Testing adding info for fitness profile', () => { + it('FR34: Testing adding info for fitness profile', () => { // wait for fitness profile data to load from backend cy.visit('/profile.html') cy.intercept('/api/users/*').as('getFitnessProfile') @@ -119,14 +157,17 @@ describe('Testing group functionality and fitness profile', () => { cy.get('textarea[name="bio"]').clear().type('This is my bio') cy.get('#btn-ok-profile').click() + // Intercepting and checking that the updated data is retrieved from backend cy.wait('@getFitnessProfile').then((interception) => { - assert.isNotNull(interception.response.body, 'API call has data') + assert.equal(interception.response.body.results[0].age, '26') + assert.equal(interception.response.body.results[0].expirience, '5') + assert.equal(interception.response.body.results[0].favorite_dicipline, 'Crossfit') + assert.equal(interception.response.body.results[0].bio, 'This is my bio') }) - // checking that the data was updated. + // checking that the data was updated frontend. cy.get('input[name="age"]').should('have.value', '26') cy.get('input[name="expirience"]').should('have.value', '5') cy.get('textarea[name="favorite_dicipline"]').should('have.value', 'Crossfit') cy.get('textarea[name="bio"]').should('have.value', 'This is my bio') }) - }) \ No newline at end of file diff --git a/frontend/cypress/integration/register_spec.js b/frontend/cypress/integration/register_spec.js index 3dc6558a4cfecbe0ca6a136e7119c233c8519c65..9edcfaba62840db9a5489c12b6a35b0bdbea5725 100644 --- a/frontend/cypress/integration/register_spec.js +++ b/frontend/cypress/integration/register_spec.js @@ -1,80 +1,157 @@ + +/** + * Helper function to help determine whether registration was successful or not. + * It intercepts the POST requesst to the /users/ API and checks if the + * request was successful and thus the response should have a status code of 201 + * orif it failed and thus should have a status code of 400 + * @param {integer} code is a response status code, either 201 or 400 + */ +Cypress.Commands.add('register', (code) => { + cy.intercept({method: 'POST', url:'/api/users/'}).as('postUser') + cy.get('#btn-create-account').click() + cy.wait('@postUser').its('response.statusCode').should('eq', code) + if (code == 201) { + cy.visit('/logout.html') + } +}) + +Cypress.Commands.add('visitRegister', () => { + cy.visit('/register.html') + cy.inputValidName() + cy.get('input[name="email"]').type('test@test.test') + cy.get('input[name="password"]').type('secure') + cy.get('input[name="password1"]').type('secure') +}) + +/** + * Helper function to generate a unique name to avoid "username already exists" + */ +Cypress.Commands.add('inputValidName', () => { + const uuid = () => Cypress._.random(0, 1e6) + const id = uuid() + const name = `username${id}` + cy.get('input[name="username"]').clear().type(name) +}) + describe('Testing boundary value on register page', () => { beforeEach(() => { cy.visit('/register.html') - /* - cy.get('input[name="username"]') - .type('simen') - cy.get('input[name="email"]') - .type('test@test.test') - cy.get('input[name="password"]') - .type('secure') - cy.get('input[name="password1"]') - .type('secure') - cy.get('input[name="phone_number"]') - .type('12345678') - cy.get('input[name="country"]') - .type('Norway') - cy.get('input[name="city"]') - .type('Trondheim') - cy.get('input[name="street_address"]') - .type('My Street') - */ + // adding valid data to the required input fields + cy.inputValidName() + cy.get('input[name="password"]').type('secure') + cy.get('input[name="password1"]').type('secure') }) + it('Testing boundaries for username', () => { + // input length lower bound + cy.get('input[name="username"]').clear() + // register and check that response status code was 400 + cy.register(400) + // testing that the response body gives the right error response for username + cy.get('@postUser').then((interception) => { + assert.equal(interception.response.body.username, 'This field may not be blank.') + }) + // checking that the error response is visible on the page. + cy.contains('This field may not be blank.') + cy.visitRegister() + // Testing with 1 character + cy.get('input[name="username"]').clear().type('s') + cy.register(201) + cy.visitRegister() - it('Testing that all HTML form fields have lower boundary length 1', () => { - // Sending an empty form should give 8 invalid input validation errors - cy.get('#btn-create-account') - .click() - // Since all are required, then 8 fields should be invalid. - cy.get('input:invalid').should('have.length', 8) + // input length upper bound + // testing with 151 characters + cy.get('input[name="username"]').clear().type('OsLqErW9DfJcme7NJapjQ81SUcjCJvoCtbrMp1sQCGypyGNf4XM97JjGlg4I1VlDR5JFGeUYMTClcoSCKeAxyC21GKsCgpFHl2UulwtHudoC760umqQjGjK9OEciTuS97eg3yuWjjJx3Mtg6GyQK8V1') + cy.register(400) + cy.get('@postUser').then((interception) => { + assert.equal(interception.response.body.username, 'Ensure this field has no more than 150 characters.') + }) + cy.contains('Ensure this field has no more than 150 characters.') + cy.visitRegister() + + // Testing with 150 character + cy.get('input[name="username"]').clear().type('OsLqErW9DfJcme7NJapjQ81SUcjCJvoCtbrMp1sQCGypyGNf4XM97JjGlg4I1VlDR5JFGeUYMTClcoSCKeAxyC21GKsCgpFHl2UulwtHudoC760umqQjGjK9OEciTuS97eg3yuWjjJx3Mtg6GyQK8V') + cy.register(201) }) - it('Testing input length lower boundaries for username and passwords', () => { - // Username and password length lower bound is 1 because backend model field is required - cy.get('input[name="username"]').clear() + it('Testing boundaries for passwords', () => { + // Input length lower bound testing with 1 character should work + cy.get('input[name="password"]').clear().type('s') + cy.get('input[name="password1"]').clear().type('s') + cy.register(201) + cy.visitRegister() + + // Input length lower boundary for passwords with 0 characters cy.get('input[name="password"]').clear() - cy.get('input[name="password1"]').clear() - cy.get('#btn-create-account').click() - // checks if error has been raised and rendered to user - cy.contains('Registration failed!') - cy.contains('username') - cy.contains('password') - cy.contains('password1') + cy.register(400) + cy.get('@postUser').then((interception) => { + assert.equal(interception.response.body.password, 'This field may not be blank.') + }) cy.contains('This field may not be blank.') + cy.visitRegister() - cy.visit('/register.html') - // try with input length 1, the errors should not be there because lower bound i 1 - cy.get('input[name="username"]').type('t') - cy.get('input[name="password"]').type('t') - cy.get('input[name="password1"]').type('t') - cy.get('#btn-create-account').click() - cy.contains('This field may not be blank.').should('not.exist') + cy.get('input[name="password1"]').clear() + cy.register(400) + cy.get('@postUser').then((interception) => { + assert.equal(interception.response.body.password1, 'This field may not be blank.') + }) + cy.contains('This field may not be blank.') + cy.visitRegister() }) - it('Testing input length upper boundaries for phone_number, country, city and street', () => { - // these fields have no lower boundary in backend. - // testing with 51 characters - cy.get('input[name="phone_number"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') - cy.get('input[name="country"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') - cy.get('input[name="city"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') - cy.get('input[name="street_address"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') - cy.get('#btn-create-account').click() - // checks if error has been raised and rendered to user - cy.contains('Registration failed!') - cy.contains('country') - cy.contains('city') - cy.contains('street_address') + it('Testing input length boundaries for phone_number, country, city and street', () => { + // Testing with upper bound 50 characters. Should work + cy.get('input[name="phone_number"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') + cy.register(201) + cy.visitRegister() + + cy.get('input[name="country"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') + cy.register(201) + cy.visitRegister() + + cy.get('input[name="city"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') + cy.register(201) + cy.visitRegister() + + cy.get('input[name="street_address"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') + cy.register(201) + cy.visitRegister() + + // testing with upper bound 51 characters. should raise error. + cy.get('input[name="phone_number"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') + cy.register(400) + cy.get('@postUser').then((interception) => { + assert.equal(interception.response.body.phone_number, 'Ensure this field has no more than 50 characters.') + }) cy.contains('Ensure this field has no more than 50 characters.') + cy.visitRegister() - cy.visit('/register.html') - // try with input length 50, the errors should not be there because lower bound is 50 - cy.get('input[name="username"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') - cy.get('input[name="password"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') - cy.get('input[name="password1"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') - cy.get('#btn-create-account').click() - cy.contains('Ensure this field has no more than 50 characters.').should('not.exist') + cy.get('input[name="country"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') + cy.register(400) + cy.get('@postUser').then((interception) => { + assert.equal(interception.response.body.country, 'Ensure this field has no more than 50 characters.') + }) + cy.contains('Ensure this field has no more than 50 characters.') + cy.visitRegister() + + cy.get('input[name="city"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') + cy.register(400) + cy.get('@postUser').then((interception) => { + assert.equal(interception.response.body.city, 'Ensure this field has no more than 50 characters.') + }) + cy.contains('Ensure this field has no more than 50 characters.') + cy.visitRegister() + + cy.get('input[name="street_address"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') + cy.register(400) + cy.get('@postUser').then((interception) => { + assert.equal(interception.response.body.street_address, 'Ensure this field has no more than 50 characters.') + }) + cy.contains('Ensure this field has no more than 50 characters.') + cy.visitRegister() + + // these fields have no lower boundary in backend. }) it('Testing that email field is the right format', () => { @@ -93,29 +170,22 @@ describe('Testing boundary value on register page', () => { expect($input[0].validationMessage).to.equal('') }) }) + + it('Testing that all frontend HTML form fields have lower boundary length 1', () => { + // Sending an empty form should give 8 invalid input validation errors. + // These errors are not displayed on the page, but since the HTML form fields have + // "reqired" attribute a validation message will be raised. + cy.get('input[name="username"]').clear() + cy.get('input[name="email"]').clear() + cy.get('input[name="password"]').clear() + cy.get('input[name="password1"]').clear() + cy.get('input[name="phone_number"]').clear() + cy.get('input[name="country"]').clear() + cy.get('input[name="city"]').clear() + cy.get('input[name="street_address"]').clear() -/** - * There are very few boundaries in the code so we ave assumed that some exist. - * We assume that the phone number can have max 10 digits and minimum 7. - * This means that the boundary is: - * 00000 00000 - 99999 99999 - * This test will fail because no such boundary exists in the code. - */ - it('Testing phone number boundary value', () => { - // Invalid phone number with 6 digits should return validation error - cy.get('input[name="phone_number"]').clear().type('999999').then(($input) => { - expect($input[0].validationMessage).to.not.equal('') - }) - // and should not be approved backend and redirected - cy.get('#btn-create-account').click() - cy.url().should('be.equal', 'http://localhost:9090/register.html') - - // Invalid phone number with 11 digits should return validation error - cy.get('input[name="phone_number"]').clear().type('10 000 000 000').then(($input) => { - expect($input[0].validationMessage).to.not.equal('') - }) - // and should not be approved backend and redirected cy.get('#btn-create-account').click() - cy.url().should('be.equal', 'http://localhost:9090/register.html') + // Since all are required, then 8 fields should be invalid. + cy.get('input:invalid').should('have.length', 8) }) }) \ No newline at end of file diff --git a/frontend/cypress/integration/two_way_domain_spec.js b/frontend/cypress/integration/two_way_domain_spec.js index 17a8dd7835a6379d47be287c73b3870a5fb9ba39..884a36670a069815ac50823265298ac984ebb7b9 100644 --- a/frontend/cypress/integration/two_way_domain_spec.js +++ b/frontend/cypress/integration/two_way_domain_spec.js @@ -13,6 +13,9 @@ let address = ['street_address', 'MyAddress', 'Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS6 /** * function to help determine whether registration was successful or not. + * It intercepts the POST requesst to the /users/ API and checks if the + * request was successful and thus the response should have a status code of 201 + * orif it failed and thus should have a status code of 400 * @param {integer} code is a response status code, either 201 or 400 * @param {list} inputList is one of the lists above * @param {integer} input is the index of the input being used in the inputList