Skip to content
Snippets Groups Projects
Commit 8ce0d65f authored by Simen's avatar Simen
Browse files

Fixed som tests and added better assertions

parent 9da4d639
Branches
No related tags found
1 merge request!5Test/task3
Pipeline #167200 passed
/** /**
* The user should be able to view all of the details, files, and comments * Helper function for logging in.
* 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.
*/ */
Cypress.Commands.add('login', (username, password) => { Cypress.Commands.add('login', (username, password) => {
cy.visit('/login.html') cy.visit('/login.html')
cy.get('input[name="username"]').type(username) cy.get('input[name="username"]').type(username)
cy.get('input[name="password"]').type(password) cy.get('input[name="password"]').type(password)
cy.get('#btn-login').click() cy.get('#btn-login').click()
cy.url().should('contain', '/workouts.html') cy.url().should('contain', '/workouts.html')
cy.intercept('/api/workouts/*').as('getWorkouts')
cy.wait('@getWorkouts')
}) })
Cypress.Commands.add('logout', () => { Cypress.Commands.add('logout', () => {
...@@ -24,19 +16,19 @@ Cypress.Commands.add('logout', () => { ...@@ -24,19 +16,19 @@ Cypress.Commands.add('logout', () => {
describe('Testing group functionality and fitness profile', () => { describe('Testing group functionality and fitness profile', () => {
beforeEach(() => { 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. // athlete needs to have user "coach" as coach.
cy.login('athlete', 'secure') cy.login('athlete', 'secure')
// cy.login('coach', 'secure') // cy.login('coach', 'secure')
// Adding test data
// three workouts with same owner but different visibility
cy.get('#btn-create-workout').click() cy.get('#btn-create-workout').click()
cy.get('input[name="name"]').type("My public workout") cy.get('input[name="name"]').type("My public workout")
cy.get('input[name="date"]').type('2017-06-01T08:30') cy.get('input[name="date"]').type('2017-06-01T08:30')
cy.get('textarea[name="notes"]').type('This is a note') cy.get('textarea[name="notes"]').type('This is a note')
cy.get('#inputVisibility').select('Public') cy.get('#inputVisibility').select('Public')
cy.get('#btn-ok-workout').click() cy.get('#btn-ok-workout').click()
cy.intercept('/api/workouts/').as('getWorkouts')
cy.wait('@getWorkouts')
cy.get('#btn-create-workout').click() cy.get('#btn-create-workout').click()
cy.get('input[name="name"]').type("My private workout") cy.get('input[name="name"]').type("My private workout")
...@@ -44,8 +36,6 @@ describe('Testing group functionality and fitness profile', () => { ...@@ -44,8 +36,6 @@ describe('Testing group functionality and fitness profile', () => {
cy.get('textarea[name="notes"]').type('This is a note') cy.get('textarea[name="notes"]').type('This is a note')
cy.get('#inputVisibility').select('Private') cy.get('#inputVisibility').select('Private')
cy.get('#btn-ok-workout').click() cy.get('#btn-ok-workout').click()
cy.intercept('/api/workouts/').as('getWorkouts')
cy.wait('@getWorkouts')
cy.get('#btn-create-workout').click() cy.get('#btn-create-workout').click()
cy.get('input[name="name"]').type("My coach workout") cy.get('input[name="name"]').type("My coach workout")
...@@ -53,34 +43,17 @@ describe('Testing group functionality and fitness profile', () => { ...@@ -53,34 +43,17 @@ describe('Testing group functionality and fitness profile', () => {
cy.get('textarea[name="notes"]').type('This is a note') cy.get('textarea[name="notes"]').type('This is a note')
cy.get('#inputVisibility').select('Coach') cy.get('#inputVisibility').select('Coach')
cy.get('#btn-ok-workout').click() cy.get('#btn-ok-workout').click()
cy.intercept('/api/workouts/').as('getWorkouts')
cy.wait('@getWorkouts')
}) })
/**
afterEach(() => { * This test fails because the visibility does not workas intended.
/*
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()
*/ */
it('Testing visibility as owner, coach, user, and guest', () => {
cy.logout()
})
it('Testing visibility', () => {
// testing visibility as owner // testing visibility as owner
cy.contains('My public workout') cy.contains('My public workout')
//cy.contains('My coach workout') cy.contains('My coach workout')
//cy.contains('My private workout') cy.contains('My private workout')
// testing visibility as coach // testing visibility as coach
cy.logout() cy.logout()
...@@ -96,8 +69,6 @@ describe('Testing group functionality and fitness profile', () => { ...@@ -96,8 +69,6 @@ describe('Testing group functionality and fitness profile', () => {
// testing visibility as visitor // testing visibility as visitor
cy.logout() cy.logout()
cy.visit('workouts.html') cy.visit('workouts.html')
cy.intercept('/api/workouts/*').as('getWorkouts') cy.contains('My public workout')
cy.wait('@getWorkouts')
//cy.contains('My public workout')
}) })
}) })
\ No newline at end of file
/**
* Helper function to login as a user and receive tokens and
* necesarry authentication.
*/
Cypress.Commands.add('login', (username, password) => { Cypress.Commands.add('login', (username, password) => {
cy.visit('/login.html') cy.visit('/login.html')
cy.get('input[name="username"]').type(username) cy.get('input[name="username"]').type(username)
cy.get('input[name="password"]').type(password) cy.get('input[name="password"]').type(password)
cy.intercept({method: 'POST', url:'/api/token/'}).as('postToken')
cy.get('#btn-login').click() 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', () => { describe('Testing boundary value on view/edit exercise page', () => {
beforeEach(() => { beforeEach(() => {
//wait for browser to store tokens. cy.login('user', 'secure')
cy.intercept('/api/workouts/*').as('getWorkouts') // Wait for the view/edit page to load
cy.login('testuser', 'secure')
cy.wait('@getWorkouts')
// wait for the exercise to be rertrieved from backend.
cy.visit('/exercise.html?id=1') cy.visit('/exercise.html?id=1')
cy.intercept('/api/exercises/*').as('getExercises') cy.intercept('/api/exercises/*').as('getExercises')
cy.wait('@getExercises') cy.wait('@getExercises').its('response.statusCode').should('eq', 200)
// enable editing // enable editing
cy.get('#btn-edit-exercise').click() cy.get('#btn-edit-exercise').click()
}) })
...@@ -31,46 +39,82 @@ describe('Testing boundary value on view/edit exercise page', () => { ...@@ -31,46 +39,82 @@ describe('Testing boundary value on view/edit exercise page', () => {
// testing for 51 // testing for 51
cy.get('input[name="unit"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') 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.') cy.contains('Ensure this field has no more than 50 characters.')
// testing for 50 // testing for 50
cy.get('input[name="unit"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') cy.get('input[name="unit"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65')
cy.get('#btn-ok-exercise').click() cy.edit(200)
// if valid input then edit button should appear again after clickin the OK button cy.get('input[name="unit"]').should('have.value', 'Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65')
cy.wait('@getExercises')
cy.get('#btn-edit-exercise').should('be.visible')
}) })
it('Testing lower boundaries for input length for Unit', () => { it('Testing lower boundaries for input length for Unit', () => {
// testing for 0 // testing for 0
cy.get('input[name="unit"]').clear() 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.') cy.contains('This field may not be blank.')
// testing for 1 // testing for 1
cy.get('input[name="unit"]').clear().type('1') cy.get('input[name="unit"]').clear().type('Y')
cy.get('#btn-ok-exercise').click() cy.edit(200)
// if valid input then edit button should appear again after clickin the OK button cy.get('input[name="unit"]').should('have.value', 'Y')
cy.get('#btn-edit-exercise').should('be.visible')
}) })
/** /**
* The lower boundaries on duration and calories are not enforced and * The lower boundaries on duration and calories are not enforced and
* therefore the tests will fail. * 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) => { cy.get('input[name="duration"]').clear().type('-1').then(($input) => {
expect($input[0].validationMessage).to.equal('[Error message]') expect($input[0].validationMessage).to.equal('[Error message]')
}) })
cy.get('input[name="duration"]').clear().type('0').then(($input) => { cy.get('input[name="duration"]').clear().type('0').then(($input) => {
expect($input[0].validationMessage).to.equal('') 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) => { cy.get('input[name="calories"]').clear().type('-1').then(($input) => {
expect($input[0].validationMessage).to.equal('[Error message]') expect($input[0].validationMessage).to.equal('[Error message]')
}) })
cy.get('input[name="calories"]').clear().type('0').then(($input) => { cy.get('input[name="calories"]').clear().type('0').then(($input) => {
expect($input[0].validationMessage).to.equal('') 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
...@@ -2,41 +2,47 @@ Cypress.Commands.add('login', (username, password) => { ...@@ -2,41 +2,47 @@ Cypress.Commands.add('login', (username, password) => {
cy.visit('/login.html') cy.visit('/login.html')
cy.get('input[name="username"]').type(username) cy.get('input[name="username"]').type(username)
cy.get('input[name="password"]').type(password) cy.get('input[name="password"]').type(password)
cy.intercept({method: 'POST', url:'/api/token/'}).as('postToken')
cy.get('#btn-login').click() cy.get('#btn-login').click()
cy.url().should('contain', '/workouts.html') cy.wait('@postToken').its('response.statusCode').should('eq', 200)
cy.intercept('/api/workouts/*').as('getWorkouts')
cy.wait('@getWorkouts')
}) })
describe('Testing group functionality and fitness profile', () => { describe('Testing group functionality and fitness profile', () => {
beforeEach(() => { beforeEach(() => {
cy.login('testuser', 'secure') cy.login('user', 'secure')
// wait for the exercise to be rertrieved from backend. // wait for the exercise to be rertrieved from backend.
cy.visit('/groups.html') cy.visit('/groups.html')
cy.intercept('/api/groups/').as('getGroups') cy.intercept('/api/groups/').as('getGroups')
cy.wait('@getGroups') cy.wait('@getGroups')
}) })
it('Testing creating new group', () => { it('FR29: Testing creating new group', () => {
cy.get('#btn-create-group').click() cy.get('#btn-create-group').click()
cy.url().should('contain', '/group.html') cy.url().should('contain', '/group.html')
// typing data for new group // typing data for new group
cy.get('input[name="name"]').type('My Group') cy.get('input[name="name"]').type('My Group')
cy.get('textarea[name="description"]').type('This is 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() cy.get('#btn-ok-group').click()
// waiting for response from backend and checking if group was created. // 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.url().should('contain', '/groups.html')
cy.intercept('/api/groups/').as('getGroups') 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('My Group')
cy.contains('This is 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 // Finding the group to edit and clicking on it
cy.url().should('contain', '/groups.html')
cy.contains('My Group').click() cy.contains('My Group').click()
cy.url().should('include', '/groupContent.html?id=') cy.url().should('include', '/groupContent.html?id=')
...@@ -50,58 +56,90 @@ describe('Testing group functionality and fitness profile', () => { ...@@ -50,58 +56,90 @@ describe('Testing group functionality and fitness profile', () => {
cy.get('#btn-edit-group').click() cy.get('#btn-edit-group').click()
cy.get('input[name="name"]').clear().type('My Group (edited)') cy.get('input[name="name"]').clear().type('My Group (edited)')
cy.get('textarea[name="description"]').clear().type('This is my group (edited)') cy.get('textarea[name="description"]').clear().type('This is my group (edited)')
// confirming the edit and checking that i is updated // 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.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.visit('/groups.html')
cy.wait('@getGroups')
cy.contains('My Group (edited)') cy.contains('My Group (edited)')
cy.contains('This is 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.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('#btn-add-content').click()
cy.get('input[name="title"]').type('My Content') cy.get('input[name="title"]').clear().type('My Content')
cy.get('textarea[name="description"]').type('This is content description') 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.get('#btn-ok-addcontent').click()
cy.wait('@postContent').its('response.statusCode').should('eq', 201)
cy.url().should('contain', '/groupContent.html?id=') cy.url().should('contain', '/groupContent.html?id=')
cy.intercept('/api/content/*').as('getContent') 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('My Content')
cy.contains('This is content description') 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. // finding the right group and content to post a comment to.
cy.contains('My Group (edited)').click() cy.contains('My Group (edited)').click()
cy.intercept('/api/content/*').as('getContent')
cy.wait('@getContent')
cy.contains('My Content').click() cy.contains('My Content').click()
cy.url().should('include', '/contentcomments.html?id=') cy.url().should('include', '/contentcomments.html?id=')
// typing and adding a comment // typing and adding a comment
cy.get('textarea[name="comment"]').type('This is 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.get('#btn-add-comment').click()
cy.wait('@postComment').its('response.statusCode').should('eq', 201)
cy.intercept('/api/comment/*').as('getComments') cy.intercept('/api/comment/*').as('getComments')
// check if comment was retrieved from backend
cy.wait('@getComments').then((interception) => { 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 // check if comment was added
cy.contains('This is a comment') cy.contains('This is a comment')
/*
// liking content // liking content
cy.intercept('/api/like/').as('like')
cy.get('#btn-like').click() cy.get('#btn-like').click()
cy.wait('@like')
// liking again should not work
cy.intercept('/api/like/').as('like') 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 // wait for fitness profile data to load from backend
cy.visit('/profile.html') cy.visit('/profile.html')
cy.intercept('/api/users/*').as('getFitnessProfile') cy.intercept('/api/users/*').as('getFitnessProfile')
...@@ -119,14 +157,17 @@ describe('Testing group functionality and fitness profile', () => { ...@@ -119,14 +157,17 @@ describe('Testing group functionality and fitness profile', () => {
cy.get('textarea[name="bio"]').clear().type('This is my bio') cy.get('textarea[name="bio"]').clear().type('This is my bio')
cy.get('#btn-ok-profile').click() cy.get('#btn-ok-profile').click()
// Intercepting and checking that the updated data is retrieved from backend
cy.wait('@getFitnessProfile').then((interception) => { 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="age"]').should('have.value', '26')
cy.get('input[name="expirience"]').should('have.value', '5') cy.get('input[name="expirience"]').should('have.value', '5')
cy.get('textarea[name="favorite_dicipline"]').should('have.value', 'Crossfit') cy.get('textarea[name="favorite_dicipline"]').should('have.value', 'Crossfit')
cy.get('textarea[name="bio"]').should('have.value', 'This is my bio') cy.get('textarea[name="bio"]').should('have.value', 'This is my bio')
}) })
}) })
\ No newline at end of file
/**
* 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', () => { describe('Testing boundary value on register page', () => {
beforeEach(() => { beforeEach(() => {
cy.visit('/register.html') cy.visit('/register.html')
/* // adding valid data to the required input fields
cy.get('input[name="username"]') cy.inputValidName()
.type('simen') cy.get('input[name="password"]').type('secure')
cy.get('input[name="email"]') cy.get('input[name="password1"]').type('secure')
.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')
*/
}) })
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', () => { // input length upper bound
// Sending an empty form should give 8 invalid input validation errors // testing with 151 characters
cy.get('#btn-create-account') cy.get('input[name="username"]').clear().type('OsLqErW9DfJcme7NJapjQ81SUcjCJvoCtbrMp1sQCGypyGNf4XM97JjGlg4I1VlDR5JFGeUYMTClcoSCKeAxyC21GKsCgpFHl2UulwtHudoC760umqQjGjK9OEciTuS97eg3yuWjjJx3Mtg6GyQK8V1')
.click() cy.register(400)
// Since all are required, then 8 fields should be invalid. cy.get('@postUser').then((interception) => {
cy.get('input:invalid').should('have.length', 8) 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()
it('Testing input length lower boundaries for username and passwords', () => { // Testing with 150 character
// Username and password length lower bound is 1 because backend model field is required cy.get('input[name="username"]').clear().type('OsLqErW9DfJcme7NJapjQ81SUcjCJvoCtbrMp1sQCGypyGNf4XM97JjGlg4I1VlDR5JFGeUYMTClcoSCKeAxyC21GKsCgpFHl2UulwtHudoC760umqQjGjK9OEciTuS97eg3yuWjjJx3Mtg6GyQK8V')
cy.get('input[name="username"]').clear() cy.register(201)
})
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="password"]').clear()
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.get('input[name="password1"]').clear() cy.get('input[name="password1"]').clear()
cy.get('#btn-create-account').click() cy.register(400)
// checks if error has been raised and rendered to user cy.get('@postUser').then((interception) => {
cy.contains('Registration failed!') assert.equal(interception.response.body.password1, 'This field may not be blank.')
cy.contains('username') })
cy.contains('password')
cy.contains('password1')
cy.contains('This field may not be blank.') cy.contains('This field may not be blank.')
cy.visitRegister()
})
cy.visit('/register.html') it('Testing input length boundaries for phone_number, country, city and street', () => {
// try with input length 1, the errors should not be there because lower bound i 1 // Testing with upper bound 50 characters. Should work
cy.get('input[name="username"]').type('t') cy.get('input[name="phone_number"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65')
cy.get('input[name="password"]').type('t') cy.register(201)
cy.get('input[name="password1"]').type('t') cy.visitRegister()
cy.get('#btn-create-account').click()
cy.contains('This field may not be blank.').should('not.exist') 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()
it('Testing input length upper boundaries for phone_number, country, city and street', () => { cy.get('input[name="country"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651')
// these fields have no lower boundary in backend. cy.register(400)
// testing with 51 characters cy.get('@postUser').then((interception) => {
cy.get('input[name="phone_number"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651') assert.equal(interception.response.body.country, 'Ensure this field has no more than 50 characters.')
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')
cy.contains('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') cy.get('input[name="city"]').clear().type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY651')
// try with input length 50, the errors should not be there because lower bound is 50 cy.register(400)
cy.get('input[name="username"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') cy.get('@postUser').then((interception) => {
cy.get('input[name="password"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') assert.equal(interception.response.body.city, 'Ensure this field has no more than 50 characters.')
cy.get('input[name="password1"]').type('Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS63PyqFiZzjzerqcY65') })
cy.get('#btn-create-account').click() cy.contains('Ensure this field has no more than 50 characters.')
cy.contains('Ensure this field has no more than 50 characters.').should('not.exist') 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', () => { it('Testing that email field is the right format', () => {
...@@ -94,28 +171,21 @@ describe('Testing boundary value on register page', () => { ...@@ -94,28 +171,21 @@ describe('Testing boundary value on register page', () => {
}) })
}) })
/** it('Testing that all frontend HTML form fields have lower boundary length 1', () => {
* There are very few boundaries in the code so we ave assumed that some exist. // Sending an empty form should give 8 invalid input validation errors.
* We assume that the phone number can have max 10 digits and minimum 7. // These errors are not displayed on the page, but since the HTML form fields have
* This means that the boundary is: // "reqired" attribute a validation message will be raised.
* 00000 00000 - 99999 99999 cy.get('input[name="username"]').clear()
* This test will fail because no such boundary exists in the code. cy.get('input[name="email"]').clear()
*/ cy.get('input[name="password"]').clear()
it('Testing phone number boundary value', () => { cy.get('input[name="password1"]').clear()
// Invalid phone number with 6 digits should return validation error cy.get('input[name="phone_number"]').clear()
cy.get('input[name="phone_number"]').clear().type('999999').then(($input) => { cy.get('input[name="country"]').clear()
expect($input[0].validationMessage).to.not.equal('') cy.get('input[name="city"]').clear()
}) cy.get('input[name="street_address"]').clear()
// 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.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
...@@ -13,6 +13,9 @@ let address = ['street_address', 'MyAddress', 'Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS6 ...@@ -13,6 +13,9 @@ let address = ['street_address', 'MyAddress', 'Ye9cxDpRYmw1kaQoFxTtMs40jUgo0SiS6
/** /**
* function to help determine whether registration was successful or not. * 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 {integer} code is a response status code, either 201 or 400
* @param {list} inputList is one of the lists above * @param {list} inputList is one of the lists above
* @param {integer} input is the index of the input being used in the inputList * @param {integer} input is the index of the input being used in the inputList
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment