Skip to content

Commit

Permalink
Fix loading of resources that have encoded chars in id
Browse files Browse the repository at this point in the history
Signed-off-by: Dinika Saxena <[email protected]>
  • Loading branch information
Dinika committed Feb 25, 2024
1 parent 5e83b58 commit 51d4656
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 41 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ a. To run the tests in headed mode:
yarn cy:open
```

If you encounter issues with `project:setup` or `resources:create` tasks because of SSL or certificate errors when running the tests locally, try the following:

```sh
NODE_TLS_REJECT_UNAUTHORIZED=0 yarn cy:open
```

b. To run the tests in headless mode:

```sh
Expand Down
22 changes: 22 additions & 0 deletions c.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"use_existing_delta_instance": false,
"NEXUS_API_URL": "https://dev.nise.bbp.epfl.ch/nexus/v1",
"users": {
"morty": {
"username": "localuser",
"password": "localuser",
"realm": {
"name": "Local",
"baseUrl": "https://dev.nise.bbp.epfl.ch/"
}
},
"morpheus": {
"username": "localuser",
"password": "localuser",
"realm": {
"name": "Local",
"baseUrl": "https://dev.nise.bbp.epfl.ch/"
}
}
}
}
9 changes: 7 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import setup, { TestUsers } from './cypress/support/setupRealmsAndUsers';
export default defineConfig({
projectId: '1iihco',
viewportWidth: 1200,
video: false,
video: true,
screenshotOnRunFailure: false,
e2e: {
baseUrl: 'http://localhost:8000',
Expand All @@ -24,6 +24,7 @@ export default defineConfig({
DEBUG: 'cypress:launcher:browsers',
ELECTRON_DISABLE_GPU: 'true',
ELECTRON_EXTRA_LAUNCH_ARGS: '--disable-gpu',
NODE_TLS_REJECT_UNAUTHORIZED: 0,
},
setupNodeEvents(on, config) {
on('before:browser:launch', (browser, launchOptions) => {
Expand Down Expand Up @@ -141,12 +142,16 @@ export default defineConfig({
token: authToken,
});

return await createResource({
const createdResource = await createResource({
nexus,
orgLabel,
projectLabel,
resource: resourcePayload,
});
if (!createResource) {
throw new Error('Test Resource was not created');
}
return createdResource;
} catch (e) {
console.log(
'Error encountered in analysisResource:create task.',
Expand Down
16 changes: 8 additions & 8 deletions cypress/e2e/AnalysisPlugin.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ describe('Report (formerly Analysis) Plugin', () => {
);
});

// after(function() {
// cy.task('project:teardown', {
// nexusApiUrl: Cypress.env('NEXUS_API_URL'),
// authToken: this.nexusToken,
// orgLabel: Cypress.env('ORG_LABEL'),
// projectLabel: this.projectLabel,
// });
// });
after(function() {
cy.task('project:teardown', {
nexusApiUrl: Cypress.env('NEXUS_API_URL'),
authToken: this.nexusToken,
orgLabel: Cypress.env('ORG_LABEL'),
projectLabel: this.projectLabel,
});
});

it('user can add a report with name, description and files, categories, types', function() {
cy.visit(
Expand Down
23 changes: 13 additions & 10 deletions cypress/e2e/ResourceContainer.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Resource } from '@bbp/nexus-sdk';

describe('Resource with id that contains URL encoded characters', () => {
const resourceIdWithEncodedCharacters =
'https://hello.lol/https%3A%2F%2Fencoded.url%2Fwow';
Expand Down Expand Up @@ -41,8 +39,6 @@ describe('Resource with id that contains URL encoded characters', () => {
orgLabel,
projectLabel,
resourcePayload,
}).then((resource: Resource) => {
cy.wrap(resource['@id']).as('fullResourceId');
});
}
);
Expand All @@ -53,7 +49,7 @@ describe('Resource with id that contains URL encoded characters', () => {

beforeEach(() => {
cy.login(
`${Cypress.env('users').morty.username}-report-plugin`,
`${Cypress.env('users').morty.username}-studio`,
Cypress.env('users').morty.realm,
Cypress.env('users').morty.username,
Cypress.env('users').morty.password
Expand All @@ -78,8 +74,9 @@ describe('Resource with id that contains URL encoded characters', () => {
cy.contains('[]');
}

it('resource opens when user clicks on resource row in MyData table', function() {
it.only('resource opens when user clicks on resource row in MyData table', function() {
cy.visit(`/`);
cy.findByText('Neuron Morphology');

cy.findAllByText(new RegExp(displayName))
.first()
Expand All @@ -90,8 +87,9 @@ describe('Resource with id that contains URL encoded characters', () => {
});
});

it('resource with any id opens when user clicks on resource row in Search table', function() {
cy.visit(`/search?layout=Neuron%20Morphology`);
it.only('resource with any id opens when user clicks on resource row in Search table', function() {
cy.visit(`/`);
cy.findByText('Neuron Morphology').click();

cy.findAllByTestId('search-table-row')
.first()
Expand All @@ -114,6 +112,7 @@ describe('Resource with id that contains URL encoded characters', () => {
});

it('resource opens with id resolution page', function() {
cy.visit('/');
const resolvePage = `/resolve/${encodeURIComponent(
resourceIdWithEncodedCharacters
)}`;
Expand All @@ -130,9 +129,13 @@ describe('Resource with id that contains URL encoded characters', () => {
// If many e2e tests ran together there may be many resources with same id.
// In this case the id resolution page will look different. Test accordingly.
cy.wait('@idResolution').then(interception => {
// expect(interception.response.body).to.equal(200);
// expect(interception.response.statusMessage).to.equal(200);
expect(interception.response.statusCode).to.equal(200);
const resolvedResources = interception.response.body._results;

if (resolvedResources.length === 1) {
cy.log(`Resolved resources delta response`, interception.response.body);
console.log('Resolved resources delta', interception.response.body);
if (resolvedResources?.length === 1) {
testResourceDataInJsonViewer();
} else {
// Multiple resources with same id found.
Expand Down
5 changes: 5 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ yarn run cy:ci

6. You can also navigate to <http://fusion.test:8000> in your browser to see the same instance of fusion that cypress is testing.

NOTE:

- Depending on the scenario you want to test, you might want to remove/rename the `cypress.env.json` (or set `use_existing_delta_instance` key to `false`)
- If there are issues with logging into http://fusion.test:8000, make sure your chrome browser has the `--unsafely-treat-insecure-origin-as-secure` flag set to `http://keycloak.test:8080`

7. Remember to stop the services once done:

```sh
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"e2e:open": "cypress open",
"e2e:run": "cypress run --config-file cypress.config.ts",
"e2e:ci": "echo | sudo docker exec --user=$UID -t cypress cypress run --headless --config-file cypress.config.ts --browser chrome",
"cy:ci": "echo | sudo docker exec --user=$UID -t cypress cypress run --config-file cypress.config.ts --browser chrome",
"e2e:ps": "echo | cypress run --config-file cypress-public-studios.config.ts --browser chrome --spec \"cypress/e2e/PublicStudios.cy.ts\"",
"e2e:ui": "API_ENDPOINT=http://test start-server-and-test dev http://localhost:8000 cy:run"
},
Expand Down Expand Up @@ -66,7 +67,7 @@
"deep-object-diff": "^1.1.0",
"express": "^4.18.2",
"handlebars": "^4.7.7",
"history": "^4.7.2",
"history": "4.5.1",
"https-browserify": "^1.0.0",
"json2csv": "^5.0.5",
"jwt-decode": "^2.2.0",
Expand Down Expand Up @@ -228,7 +229,8 @@
},
"resolutions": {
"d3-interpolate": "2.0.1",
"headers-polyfill": "3.0.10"
"headers-polyfill": "3.0.10",
"history": "4.5.1"
},
"overrides": {
"d3-interpolate": "2.0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@testing-library/jest-dom';
import { vi, describe } from 'vitest';
import { NexusProvider } from '@bbp/react-nexus';
import { createBrowserHistory } from 'history';
import { createMemoryHistory } from 'history';
import { createNexusClient } from '@bbp/nexus-sdk';
import { Provider } from 'react-redux';
import { QueryClient, QueryClientProvider } from 'react-query';
Expand All @@ -26,7 +26,7 @@ import { setupServer } from 'msw/node';
describe(
'workSpaceMenu',
() => {
const history = createBrowserHistory({ basename: '/' });
const history = createMemoryHistory({});
const contextValue: StudioContextType = {
orgLabel: 'org',
projectLabel: 'project',
Expand Down
47 changes: 30 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6789,17 +6789,16 @@ hey-listen@^1.0.8:
resolved "https://registry.yarnpkg.com/hey-listen/-/hey-listen-1.0.8.tgz#8e59561ff724908de1aa924ed6ecc84a56a9aa68"
integrity sha512-COpmrF2NOg4TBWUJ5UVyaCU2A88wEMkUPK4hNqyCkqHbxT92BbvfjoSozkAIIm6XhicGlJHhFdullInrdhwU8Q==

history@^4.7.2, history@^4.9.0:
version "4.10.1"
resolved "https://registry.yarnpkg.com/history/-/history-4.10.1.tgz#33371a65e3a83b267434e2b3f3b1b4c58aad4cf3"
integrity sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==
history@4.5.1, history@^4.9.0:
version "4.5.1"
resolved "https://registry.yarnpkg.com/history/-/history-4.5.1.tgz#44935a51021e3b8e67ebac267a35675732aba569"
integrity sha512-gfHeJeYeMzFtos61gdA1AloO0hGXPF2Yum+2FRdJvlylYQOz51OnT1zuwg9UYst1BRrONhcAh3Nmsg9iblgl6g==
dependencies:
"@babel/runtime" "^7.1.2"
invariant "^2.2.1"
loose-envify "^1.2.0"
resolve-pathname "^3.0.0"
tiny-invariant "^1.0.2"
tiny-warning "^1.0.0"
value-equal "^1.0.1"
resolve-pathname "^2.0.0"
value-equal "^0.2.0"
warning "^3.0.0"

hmac-drbg@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -7082,6 +7081,13 @@ internal-slot@^1.0.4, internal-slot@^1.0.5:
hasown "^2.0.0"
side-channel "^1.0.4"

invariant@^2.2.1:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
dependencies:
loose-envify "^1.0.0"

inversify-inject-decorators@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/inversify-inject-decorators/-/inversify-inject-decorators-3.1.0.tgz#d9941080bad77cec8a65ee29d905e4d5d73e1e95"
Expand Down Expand Up @@ -10815,10 +10821,10 @@ [email protected], resolve-global@^1.0.0:
dependencies:
global-dirs "^0.1.1"

resolve-pathname@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd"
integrity sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==
resolve-pathname@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-2.2.0.tgz#7e9ae21ed815fd63ab189adeee64dc831eefa879"
integrity sha512-bAFz9ld18RzJfddgrO2e/0S2O81710++chRMUxHjXOYKF6jTAMrUNZrEZ1PvV0zlhfjidm08iRPdTLPno1FuRg==

resolve-pkg-maps@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -12585,10 +12591,10 @@ validate-npm-package-name@^4.0.0:
dependencies:
builtins "^5.0.0"

value-equal@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-1.0.1.tgz#1e0b794c734c5c0cade179c437d356d931a34d6c"
integrity sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==
value-equal@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-0.2.1.tgz#c220a304361fce6994dbbedaa3c7e1a1b895871d"
integrity sha512-yRL36Xb2K/HmFT5Fe3M86S7mu4+a12/3l7uytUh6eNPPjP77ldPBvsAvmnWff39sXn55naRMZN8LZWRO8PWaeQ==

vary@~1.1.2:
version "1.1.2"
Expand Down Expand Up @@ -12787,6 +12793,13 @@ w3c-xmlserializer@^4.0.0:
dependencies:
xml-name-validator "^4.0.0"

warning@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
integrity sha512-jMBt6pUrKn5I+OGgtQ4YZLdhIeJmObddh6CsibPxyQ5yPZm1XExSyzC1LCNX7BzhxWgiHmizBWJTHJIjMjTQYQ==
dependencies:
loose-envify "^1.0.0"

wcwidth@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
Expand Down

0 comments on commit 51d4656

Please sign in to comment.