Skip to content

Commit

Permalink
tests: create cypress tests to check 0 day checkout
Browse files Browse the repository at this point in the history
* Adds a test to control that the 'zero day checkout' works correctly.
* Adds a test to check the creation of a cipo.

Co-Authored-by: Alicia Zangger <[email protected]>
  • Loading branch information
Alicia Zangger committed Dec 10, 2020
1 parent d4e4814 commit bcf3270
Show file tree
Hide file tree
Showing 18 changed files with 670 additions and 22 deletions.
51 changes: 51 additions & 0 deletions tests/e2e/cypress/cypress/fixtures/cipo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"on_site": {
"organisation_pid": 4,
"name": "On site",
"allow_requests": false,
"allow_checkout": true,
"checkout_duration": 0,
"policy_library_level": false,
"is_default": false
},
"extended": {
"organisation_pid": 4,
"name":"Extended",
"description":"Extended loan (3 months).",
"allow_requests":true,
"allow_checkout":true,
"checkout_duration":84,
"number_of_days_after_due_date":5,
"number_of_days_before_due_date":5,
"number_renewals":3,
"renewal_duration":84,
"reminder_fee_amount":2,
"policy_library_level":false,
"is_default":false
},
"default": {
"pid": 7,
"organisation_pid": 4,
"name":"Default",
"description":"Default circulation policy.",
"allow_requests":true,
"allow_checkout":true,
"checkout_duration":30,
"number_of_days_after_due_date":5,
"number_of_days_before_due_date":5,
"number_renewals":3,
"renewal_duration":30,
"reminder_fee_amount":2,
"policy_library_level":false,
"is_default":true
},
"no_checkout": {
"organisation_pid": 4,
"name":"No checkout",
"description":"Ebooks circulation policy.",
"allow_requests":false,
"allow_checkout":false,
"policy_library_level":false,
"is_default":false
}
}
5 changes: 3 additions & 2 deletions tests/e2e/cypress/cypress/fixtures/documents.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
"place": "Afghanistan (af)"
},
"issuance": {
"mainType": "Serial",
"mainType": "single unit",
"mainTypeCode": "rdami:1001",
"subtype": "Material unit"
"subtype": "Material unit",
"subtypeCode": "materialUnit"
},
"authors": {
"person":{
Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/cypress/cypress/fixtures/item_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"on_site": {
"pid": 11,
"type": "standard",
"name": "On site",
"description": "On site consultation",
"organisation_pid": 4
},
"default": {
"pid": 11,
"type": "standard",
"name": "Default",
"description": "Default item type",
"organisation_pid": 4
}
}
8 changes: 8 additions & 0 deletions tests/e2e/cypress/cypress/fixtures/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@
"pickupName": "Vulcan library",
"itemTypeUri": "Default",
"itemTypePid": 11
},
"starfleet_on_site": {
"code": "STARFLEET-BIB",
"location": "Default location for Starfleet library",
"locationPid": 35,
"pickupName": "Starfleet library",
"itemTypeUri": "On site",
"itemTypePid": ""
}
}
13 changes: 13 additions & 0 deletions tests/e2e/cypress/cypress/fixtures/patron_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"visitors": {
"name": "Visitor",
"description": "Visitor for on site consultation.",
"organisation_pid": 4
},
"standard": {
"name": "Standard",
"description": "Standard patron.",
"organisation_pid": 4,
"pid": 7
}
}
28 changes: 22 additions & 6 deletions tests/e2e/cypress/cypress/fixtures/users.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
{
"patrons": {
"james": {
"patron":{
"barcode": "cypress-1"
},
"email": "[email protected]",
"first_name": "James",
"last_name": "Kirk",
"barcode": "cypress-1",
"initials": "JK"
},
"nyota": {
"email": "[email protected]",
"first_name": "Nyota",
"last_name": "Uhura",
"barcode": "cypress-2",
"initials": "NU"
"patron": {
"barcode":"cypress-2",
"communication_channel":"email",
"communication_language":"eng",
"expiration_date":"2023-10-07",
"type": 7
},
"birth_date":"1932-12-28",
"city":"Betelgeuse",
"email":"[email protected]",
"first_name":"Nyota",
"last_name":"Uhura",
"phone":"+41324883123",
"pid":"53",
"postal_code":"4242",
"roles":["patron"],
"street":"Milky Way street",
"user_id":56,
"username":"Nyota"
}
},
"librarians": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ describe('Circulation scenario A: standard loan', function() {
*/
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Go to requests list
cy.visit('/professional/circulation/requests');
cy.get('#user-services-menu').click();
cy.get('#requests-menu').click();
// Check that the document is present
cy.get('#request-' + this.itemBarcode + ' [name="barcode"]').should('contain', this.itemBarcode);
// Enter the barcode and validate
Expand All @@ -113,7 +114,7 @@ describe('Circulation scenario A: standard loan', function() {
cy.get('#user-services-menu').click();
cy.get('#users-menu').click();
// Go to James patron profile
cy.get('#' + this.users.patrons.james.barcode + '-loans').click();
cy.get('#' + this.users.patrons.james.patron.barcode + '-loans').click();
// Click on tab called "To pick up"
cy.get('#pick-up-tab').click();
// The item should be present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
// Login as librarian (Leonard)
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Go to requests list
cy.visit('/professional/circulation/requests');
cy.get('#user-services-menu').click();
cy.get('#requests-menu').click();
// Check that the document is present
cy.get('#request-' + this.itemBarcode + ' [name="barcode"]').should('contain', this.itemBarcode);
// Enter the barcode and validate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/// <reference types="Cypress" />
/*
RERO ILS
Copyright (C) 2020 RERO
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

before(function () {
// Run once before all
// Use to load fixtures and set variable needed in all tests
cy.fixture('users').then(function (users) {
this.users = users;
});
cy.fixture('common').then(function (common) {
this.common = common;
});
cy.fixture('patron_types').then(function (patronTypes) {
this.patronTypes = patronTypes;
});
cy.fixture('cipo').then(function (cipo) {
this.cipo = cipo;
});
cy.fixture('item_types').then(function (itemTypes) {
this.itemTypes = itemTypes;
});
cy.fixture('items').then(function (items) {
this.items = items;
});
cy.fixture('documents').then(function (documents) {
this.documents = documents;
});
this.currentDate = cy.getCurrentDateAndHour();
this.itemBarcode = 'on-site-' + this.currentDate;
this.nameSuffix = ' ' + this.currentDate;
});

describe(`Test 'less than one day' checkout`, function() {
let cipoPid;
let itemTypePid;
let documentPid;
let itemPid;
let patronTypePid;

before('Login and prepare app for tests', function() {
// Login as librarian (Leonard)
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Create patron type
cy.apiCreatePatronType(this.patronTypes.visitors, this.nameSuffix);
cy.get('@getPatronTypePid').then((pid) => {
// Store pid
patronTypePid = pid;
// Apply patron type to a patron
cy.apiUpdatePatron(this.users.patrons.nyota, patronTypePid);
// Create an item type
cy.apiCreateItemType(this.itemTypes.on_site, this.nameSuffix);
cy.get('@getItemTypePid').then((pid) => {
// Store pid
itemTypePid = pid;
// Create 'on site' circulation policy
cy.apiCreateCipo(this.cipo.on_site, patronTypePid, itemTypePid, this.nameSuffix);
cy.get('@getCipoPid').then((pid) => {
// Store pid
cipoPid = pid;
});
// Create a document
cy.apiCreateDocument(this.documents.book, this.nameSuffix);
cy.get('@getDocumentPid').then((pid) => {
// Store pid
documentPid = pid;
// Create item
cy.apiCreateItem(this.items.starfleet_on_site, this.itemBarcode, pid, itemTypePid);
});
cy.get('@getItemPid').then((pid) => {
// Store item pid
itemPid = pid;
});
});
});
});

beforeEach('Preserve cookies', function() {
// Preserve authentication information between the tests
Cypress.Cookies.preserveOnce('session');
});

after('Clean data', function() {
// Remove cipo
cy.apiDeleteResources('circ_policies', cipoPid);
// Link patron with 'standard' patron type to allow 'visitor' patron type deletion
cy.apiUpdatePatron(this.users.patrons.nyota, this.users.patrons.nyota.patron.type);
// Remove patron type
cy.apiDeleteResources('patron_types', patronTypePid);
// Remove item
cy.apiDeleteResources('items', 'pid:"'+ itemPid + '"');
// Remove item type
cy.apiDeleteResources('item_types', itemTypePid);
// Remove document
cy.apiDeleteResources('documents', 'pid:"'+ documentPid + '"');
cy.logout();
});

it('The item cannot be requested', function() {
// Go to document detailed view
cy.goToProfessionalDocumentDetailView(documentPid);
// Create a request
cy.get('#item-' + this.itemBarcode + ' > [name=buttons] > [name=request]').click();
cy.get('#patronBarcode').type(this.users.patrons.nyota.patron.barcode);
cy.get('#pickupPid').select(this.items.starfleet_on_site.pickupName);
// Assert that the circ policy doesn't allow the request
cy.get('formly-validation-message').should('contain', 'Circulation policy disallows the operation.');
cy.get('#new-request-button').should('be.disabled');
cy.get('.close').click();
});

it('Checkout the item', function() {
// Go to circulation view and do a checkout
cy.get('#user-services-menu').click();
cy.get('#circulation-menu').click();
cy.scanPatronBarcodeThenItemBarcode(this.users.patrons.nyota, this.itemBarcode);
cy.get('#item-' + this.itemBarcode + ' [name=circ-info').should('contain', cy.getDateDisplayed(this.currentDate, 'en', '/'));
});

it('Checkin the item', function() {
// Checkin
cy.scanItemBarcode(this.itemBarcode);
// Assert that the item was checked in and that it is on shelf
cy.get('#item-' + this.itemBarcode).should('contain', this.itemBarcode);
cy.get('#item-' + this.itemBarcode).should('contain', 'on shelf');
cy.get('#item-' + this.itemBarcode).should('contain', 'checked in');
});
});
Loading

0 comments on commit bcf3270

Please sign in to comment.