Skip to content

Commit

Permalink
#242: fixing tests for oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-may committed Oct 1, 2024
1 parent efbcbd4 commit 1cc3cf9
Showing 1 changed file with 71 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import selectors from "../support/selectors";
context("Transcript Export Tests", () => {

beforeEach(() => {
Cypress.Commands.add("getFileName", (projName) => {
const userName = Cypress.env('oauthMode') ? 'foo bar (foo)' : 'user1'
return `./cypress/downloads/${projName} - ${userName} - Transcript.pdf`
})
})
if (Utils.skillsServiceVersionLaterThan('3.1.0')) {
const expectedHeaderAndFooter = 'For All Dragons enjoyment'
Expand All @@ -37,7 +41,7 @@ context("Transcript Export Tests", () => {
cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click()

Cypress.Commands.add("readTranscript", () => {
const pathToPdf = `./cypress/downloads/${projName} - user1 - Transcript.pdf`
const pathToPdf = cy.getFileName(projName)
cy.readFile(pathToPdf, { timeout: 10000 }).then(() => {
// file exists and was successfully read
cy.log(`Transcript [${pathToPdf}] Found!`)
Expand Down Expand Up @@ -85,7 +89,7 @@ context("Transcript Export Tests", () => {

cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click()
Cypress.Commands.add("readTranscript", () => {
const pathToPdf = `cypress/downloads/${projName} - user1 - Transcript.pdf`
const pathToPdf = cy.getFileName(projName)
cy.readFile(pathToPdf, { timeout: 10000 }).then(() => {
// file exists and was successfully read
cy.log(`Transcript [${pathToPdf}] Found!`)
Expand Down Expand Up @@ -114,72 +118,74 @@ context("Transcript Export Tests", () => {
})
});

it('export user transcript - community protected header', () => {
cy.intercept('GET', '/public/config', (req) => {
req.reply((res) => {
const conf = res.body;
conf.exportHeaderAndFooter = 'For {{community.project.descriptor}} enjoyment';
res.send(conf);
if (!Cypress.env('oauthMode')) {
it('export user transcript - community protected header', () => {
cy.intercept('GET', '/public/config', (req) => {
req.reply((res) => {
const conf = res.body;
conf.exportHeaderAndFooter = 'For {{community.project.descriptor}} enjoyment';
res.send(conf);
});
}).as('getPublicConfig');
const projName = 'Export3'
cy.createDefaultTinyProject('proj1', projName)

const allDragonsUser = '[email protected]'
cy.fixture('vars.json').then((vars) => {
cy.backendLogout();
cy.backendRegister('user1', vars.defaultPass);
cy.backendLogin(vars.rootUser, vars.defaultPass, true);
cy.backendPost(`/root/users/user1/tags/dragons`, {tags: ['DivineDragon']});
cy.backendPost(`/root/users/${vars.defaultUser}/tags/dragons`, {tags: ['DivineDragon']});
cy.backendLogout();

cy.backendRegister(allDragonsUser, vars.defaultPass);
cy.backendLogout();

cy.backendLogin(vars.defaultUser, vars.defaultPass);
});
}).as('getPublicConfig');
const projName = 'Export3'
cy.createDefaultTinyProject('proj1', projName)

const allDragonsUser = '[email protected]'
cy.fixture('vars.json').then((vars) => {
cy.backendLogout();
cy.backendRegister('user1', vars.defaultPass);
cy.backendLogin(vars.rootUser, vars.defaultPass, true);
cy.backendPost( `/root/users/user1/tags/dragons`, { tags: ['DivineDragon'] });
cy.backendPost( `/root/users/${vars.defaultUser}/tags/dragons`, { tags: ['DivineDragon'] });
cy.backendLogout();

cy.backendRegister(allDragonsUser, vars.defaultPass);
cy.backendLogout();

cy.backendLogin(vars.defaultUser, vars.defaultPass);
});
cy.backendPost(`/admin/projects/proj1`, {
projectId: 'proj1',
name: projName,
enableProtectedUserCommunity: true
})

// visit client display
cy.visitSkillsDisplay();
cy.wait('@getPublicConfig')
cy.clientDisplay().find(selectors.titleSection).contains('User Skills');
cy.clientDisplay().find(selectors.myRankButton)
cy.backendPost(`/admin/projects/proj1`, {
projectId: 'proj1',
name: projName,
enableProtectedUserCommunity: true
})

cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click()
Cypress.Commands.add("readTranscript", () => {
const pathToPdf = `cypress/downloads/${projName} - Firstname LastName (user1) - Transcript.pdf`
cy.readFile(pathToPdf, { timeout: 10000 }).then(() => {
// file exists and was successfully read
cy.log(`Transcript [${pathToPdf}] Found!`)
// visit client display
cy.visitSkillsDisplay();
cy.wait('@getPublicConfig')
cy.clientDisplay().find(selectors.titleSection).contains('User Skills');
cy.clientDisplay().find(selectors.myRankButton)

cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click()
Cypress.Commands.add("readTranscript", () => {
const pathToPdf = `cypress/downloads/${projName} - Firstname LastName (user1) - Transcript.pdf`
cy.readFile(pathToPdf, {timeout: 10000}).then(() => {
// file exists and was successfully read
cy.log(`Transcript [${pathToPdf}] Found!`)
})
return cy.task('readPdf', pathToPdf)
});
const clean = (text) => {
return text.replace(/\n/g, '')
}
cy.readTranscript().then((doc) => {
expect(doc.numpages).to.equal(2)
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 0 / 5 ')
expect(clean(doc.text)).to.include('Points: 0 / 100 ')
expect(clean(doc.text)).to.include('Skills: 0 / 2 ')
expect(clean(doc.text)).to.include('user1')
expect(clean(doc.text)).to.not.include('Badges')

// should be a title on the 2nd page
expect(clean(doc.text)).to.include('Subject: Subject 0'.toUpperCase())

expect(clean(doc.text)).to.not.include(expectedHeaderAndFooter)
expect(clean(doc.text)).to.include(expectedHeaderAndFooterCommunityProtected)
expect(clean(doc.text)).to.not.include('null')
})
return cy.task('readPdf', pathToPdf)
});
const clean = (text) => {
return text.replace(/\n/g, '')
}
cy.readTranscript().then((doc) => {
expect(doc.numpages).to.equal(2)
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 0 / 5 ')
expect(clean(doc.text)).to.include('Points: 0 / 100 ')
expect(clean(doc.text)).to.include('Skills: 0 / 2 ')
expect(clean(doc.text)).to.include('user1')
expect(clean(doc.text)).to.not.include('Badges')

// should be a title on the 2nd page
expect(clean(doc.text)).to.include('Subject: Subject 0'.toUpperCase())

expect(clean(doc.text)).to.not.include(expectedHeaderAndFooter)
expect(clean(doc.text)).to.include(expectedHeaderAndFooterCommunityProtected)
expect(clean(doc.text)).to.not.include('null')
})
});
}
}
});

0 comments on commit 1cc3cf9

Please sign in to comment.