From c3bf42793f23bce08db047552b5009c32410da42 Mon Sep 17 00:00:00 2001 From: Karen Madrigal Date: Mon, 19 Dec 2022 20:41:07 -0600 Subject: [PATCH 1/2] add/put/delete peer review inbox notifications --- cypress.config.ts | 1 + .../peer-review-inbox-notif.cy.js | 155 ++++++++++++++++++ .../peer-review-inbox-notif.fixture.json | 28 ++++ 3 files changed, 184 insertions(+) create mode 100644 cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js create mode 100644 cypress/fixtures/inbox-notif-fixtures/peer-review-inbox-notif.fixture.json diff --git a/cypress.config.ts b/cypress.config.ts index 558e5b9762..132f787a6a 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -22,6 +22,7 @@ export default defineConfig({ membersAPI_workEndpoint: '/work', membersAPI_allWorksEndpoint: '/works', membersAPI_peerReviewEndpoint: '/peer-review', + membersAPI_allPeerReviewsEndpoint: '/peer-reviews', membersAPI_employmentEndpoint: '/employment', membersAPI_allEmploymentsEndpoint: '/employments', membersAPI_notifPermEndpoint: '/notification-permission', diff --git a/cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js b/cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js new file mode 100644 index 0000000000..d3d4c5acef --- /dev/null +++ b/cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js @@ -0,0 +1,155 @@ +/// + +import userData from '../../fixtures/inboxNotif-users.fixture.json' + +describe('Inbox: add/update/delete peer reviews via API', async function () { + const curlAddPeerReview = + "curl -i -H 'Content-type: application/json' -H 'Authorization: Bearer " + + userData.cyNotifPerm.clientBearer + + "' -d '" + + userData.cyNotifPerm.curlPeerReviewPath + + "' -X POST '" + + Cypress.env('membersAPI_URL') + + userData.cyNotifPerm.oid + + Cypress.env('membersAPI_peerReviewEndpoint') + + "'" + + const curlReadAllPeerReviews = + "curl -i -H 'Accept: application/json' -H 'Authorization: Bearer " + + userData.cyNotifPerm.clientBearer + + "' -X GET '" + + Cypress.env('membersAPI_URL') + + userData.cyNotifPerm.oid + + Cypress.env('membersAPI_allPeerReviewsEndpoint') + + "'" + + const curlReadSinglePeerReview = + "curl -i -H 'Accept: application/json' -H 'Authorization: Bearer " + + userData.cyNotifPerm.clientBearer + + "' -X GET '" + + Cypress.env('membersAPI_URL') + + userData.cyNotifPerm.oid + + Cypress.env('membersAPI_peerReviewEndpoint') + + '/' //here append "{PUTCODE}" + "'" + + const curlPutPeerReview = + "curl -i -H 'Content-type: application/json' -H 'Authorization: Bearer " + + userData.cyNotifPerm.clientBearer + + "' -X PUT -d '" + + userData.cyNotifPerm.curlPeerReviewUpdatePath + + "' " + + Cypress.env('membersAPI_URL') + + userData.cyNotifPerm.oid + + Cypress.env('membersAPI_peerReviewEndpoint') + + '/' //here append "{PUTCODE}" + + const curlDeletePeerReview = + "curl -i -H 'Content-type: application/json' -H 'Authorization: Bearer " + + userData.cyNotifPerm.clientBearer + + "' -X DELETE " + + Cypress.env('membersAPI_URL') + + userData.cyNotifPerm.oid + + Cypress.env('membersAPI_peerReviewEndpoint') + + '/' //here append "{PUTCODE}" + + before(() => { + //log in + cy.visit(Cypress.env('signInURL')) + cy.signin(userData.cyNotifPerm) + //go to inbox + cy.get('#cy-user-info').click() + cy.get('#cy-inbox').wait(1000).click({ force: true }) + }) + + it('Inbox notifications are received when peer review is added/updated/deleted via API', function () { + let putCode + let updatedContent + + //Client adds an work + cy.exec(curlAddPeerReview).then((response) => { + //verify curl was executed successfully + expect(response.code).to.eq(0) + //verify http response status is successful: 201 + expect(response.stdout).to.contain('HTTP/2 201') + }) + + //#1 check inbox has the notification for adding + cy.reload() + cy.wait(2000) + cy.get('app-notification').contains('YOUR RECORD').click() + cy.contains('Added').should('be.visible') + cy.get('button').contains('Archive').click() + + //Read works to grab putcode + //There should only be one work + cy.exec(curlReadAllPeerReviews).then((response) => { + //verify curl was executed successfully + expect(response.code).to.eq(0) + //verify http response status is successful: 200 + expect(response.stdout).to.contain('HTTP/2 200') + //grab put code + const responseString = response.stdout + const putcodeIndex = responseString.indexOf('peer-review/') + const putCodeStartPosition = putcodeIndex + 12 // +length + const putCodeEndPosition = responseString.indexOf('","display-index') + putCode = responseString.substring( + putCodeStartPosition, + putCodeEndPosition + ) + cy.log(putCode) + cy.exec(curlReadSinglePeerReview + putCode + "'").then((singlePR) => { + //remove non json header from string + const jsonStartIndex = singlePR.stdout.indexOf('{"created-date"') //where does the json start? + updatedContent = singlePR.stdout.substring(jsonStartIndex) + //update the employment: make a change in the content + updatedContent = updatedContent.replace( + userData.cyNotifPerm.peerReviewToBeReplaced, + userData.cyNotifPerm.peerReviewReplaceWith + ) + //write the file to use for the PUT + cy.writeFile( + userData.cyNotifPerm.peerReview_putWriteFilePath, + updatedContent + ) + }) + + //Client Updates the work + cy.exec(curlPutPeerReview + putCode).then((responsePUT) => { + //verify curl was executed successfully + expect(responsePUT.code).to.eq(0) + //verify http response status is successful: 200 + expect(responsePUT.stdout).to.contain('HTTP/2 200') + }) + //#2 verify the notification is received for updating + cy.reload() + cy.wait(2000) + cy.get('app-notification').contains('YOUR RECORD').click() + cy.contains('Updated').should('be.visible') + + //Client deletes work with that put code + cy.exec(curlDeletePeerReview + putCode).then((responseDelete) => { + //verify curl was executed successfully + expect(responseDelete.code).to.eq(0) + //verify http response status is successful: 204 + expect(responseDelete.stdout).to.contain('HTTP/2 204') + }) + //#3 verify the notification was received for deleting + cy.reload() + cy.wait(2000) + cy.get('app-notification').contains('YOUR RECORD').click() + cy.contains('Deleted').should('be.visible') + }) + }) + + after(() => { + //CLEAN INBOX: archive all notifications + cy.get('[class="control-container"]').within(() => { + cy.get('mat-checkbox').click() + }) + cy.get('button').contains('Archive').click() + cy.wait(2000) //wait for back end to complete + //log out + cy.get('#cy-user-info').click({ force: true }) + cy.get('#cy-signout').click({ force: true }) + }) +}) \ No newline at end of file diff --git a/cypress/fixtures/inbox-notif-fixtures/peer-review-inbox-notif.fixture.json b/cypress/fixtures/inbox-notif-fixtures/peer-review-inbox-notif.fixture.json new file mode 100644 index 0000000000..3162f916e4 --- /dev/null +++ b/cypress/fixtures/inbox-notif-fixtures/peer-review-inbox-notif.fixture.json @@ -0,0 +1,28 @@ +{ + "reviewer-role": "reviewer", + "review-identifiers": { + "external-id": { + "external-id-type": "source-work-id", + "external-id-value": 1234, + "external-id-url": "https://localsystem.org/1234", + "external-id-relationship": "self" + } + }, + "review-type": "review", + "review-completion-date": { + "year": 2012 + }, + "review-group-id": "issn:1741-4857", + "convening-organization": { + "name": "ORCID", + "address": { + "city": "Bethesda", + "region": "MD", + "country": "US" + }, + "disambiguated-organization": { + "disambiguated-organization-identifier": 385488, + "disambiguation-source": "RINGGOLD" + } + } +} From f2d1295744cd0cbe02f04c5b13adc6aac0ede054 Mon Sep 17 00:00:00 2001 From: Karen Madrigal Date: Tue, 20 Dec 2022 02:45:18 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A4=96=20GITHUB=20ACTIONS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js b/cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js index d3d4c5acef..d834f0397c 100644 --- a/cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js +++ b/cypress/e2e/inbox_notifications/peer-review-inbox-notif.cy.js @@ -152,4 +152,4 @@ describe('Inbox: add/update/delete peer reviews via API', async function () { cy.get('#cy-user-info').click({ force: true }) cy.get('#cy-signout').click({ force: true }) }) -}) \ No newline at end of file +})