Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into exploration-page-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
derwehr committed Jun 14, 2021
2 parents 16b70f5 + d4bccee commit 3338359
Show file tree
Hide file tree
Showing 24 changed files with 768 additions and 144 deletions.
29 changes: 7 additions & 22 deletions .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
# kmap.import-action.start-db #
- run: |
docker run -d -p 7474:7474 -p 7687:7687 \
-v ${GITHUB_WORKSPACE}/backend/docker/mount:/mnt/amos \
-v ${GITHUB_WORKSPACE}/backend/docker/plugins:/plugins \
--env NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \
--env DB_PASSWORD=amos \
--env DB_PATH=/mnt/amos/dumps/testing-dump.dump \
--env 'NEO4JLABS_PLUGINS=["apoc", "graph-data-science"]' \
--env 'NEO4J_dbms_security_procedures_unrestricted=apoc.*,gds.*' \
--env 'NEO4J_dbms_security_procedures_allowlist=apoc.*,gds.*' \
--env NEO4J_apoc_import_file_enabled=true \
--name neo4j-DB neo4j:enterprise \
/mnt/amos/load-dump.sh
- run: node build/start-database

- run: npm install -g yarn
# kmap.import-action.cache #
Expand Down Expand Up @@ -75,17 +63,14 @@ jobs:
- run: yarn install --frozen-lockfile --prefer-offline --network-timeout 1000000
working-directory: ${{ env.working-directory }}

- name: Add .env file
run: cp .env.test .env
working-directory: ${{ env.working-directory }}

- name: Wait on DB Server
run: npx wait-on http://localhost:7474
run: node backend/wait-on-db
timeout-minutes: 3

- run: yarn run test:cov
working-directory: ${{ env.working-directory }}
env:
NEO4J_SCHEME: neo4j
NEO4J_HOST: localhost
NEO4J_PORT: 7687
NEO4J_USERNAME: neo4j
NEO4J_PASSWORD: amos
NEO4J_DATABASE: neo4j
CORS_URL: http://localhost:3000
timeout-minutes: 15
22 changes: 5 additions & 17 deletions .github/workflows/frontend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,20 @@ jobs:
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

# kmap.import-action.start-db #
- run: |
docker run -d -p 7474:7474 -p 7687:7687 \
-v ${GITHUB_WORKSPACE}/backend/docker/mount:/mnt/amos \
-v ${GITHUB_WORKSPACE}/backend/docker/plugins:/plugins \
--env NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \
--env DB_PASSWORD=amos \
--env DB_PATH=/mnt/amos/dumps/testing-dump.dump \
--env 'NEO4JLABS_PLUGINS=["apoc", "graph-data-science"]' \
--env 'NEO4J_dbms_security_procedures_unrestricted=apoc.*,gds.*' \
--env 'NEO4J_dbms_security_procedures_allowlist=apoc.*,gds.*' \
--env NEO4J_apoc_import_file_enabled=true \
--name neo4j-DB neo4j:enterprise \
/mnt/amos/load-dump.sh
- run: node build/start-database


- run: yarn install --frozen-lockfile --prefer-offline --network-timeout 1000000
working-directory: ${{ env.working-directory }}
- run: yarn install --frozen-lockfile --prefer-offline --network-timeout 1000000
working-directory: ./backend

- name: Wait on DB Server
run: wait-on tcp:7687
timeout-minutes: 3

- name: Start Frontend Dev Server (detached)
run: pm2 start ./build/start-frontend-detached.js

- name: Wait on DB Server
run: node backend/wait-on-db
timeout-minutes: 3
- name: Start Backend Dev Server (detached)
run: pm2 start ./build/start-backend-detached.js

Expand Down
Binary file modified backend/docker/plugins/graph-data-science.jar
Binary file not shown.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@nestjs/config": "^0.6.3",
"@nestjs/core": "^7.6.15",
"@nestjs/platform-express": "^7.6.15",
"dotenv": "^10.0.0",
"minisearch": "^3.0.2",
"neo4j-driver": "^4.2.3",
"nest-neo4j": "^0.1.4",
Expand Down
55 changes: 55 additions & 0 deletions backend/wait-on-db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Fixed #301.
This script terminates after a successful connection to the neo4j database.
Connection details are taken from `__dirname/.env`, just like in the backend app.
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const neo4j = require('neo4j-driver');
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('dotenv').config({ path: path.join(__dirname, '.env') });

const config = {
scheme: process.env.NEO4J_SCHEME,
host: process.env.NEO4J_HOST,
port: process.env.NEO4J_PORT,
username: process.env.NEO4J_USERNAME,
password: process.env.NEO4J_PASSWORD,
};

// eslint-disable-next-line no-console
console.log(config);

async function tryConnect() {
let driver;
let session;

try {
driver = neo4j.driver(
`${config.scheme}://${config.host}:${config.port}`,
neo4j.auth.basic(config.username, config.password)
);
await driver.verifyConnectivity();

// start dummy query
session = driver.session();
await session.run('MATCH (n) RETURN n LIMIT 1');

// eslint-disable-next-line no-console
console.log('Connection successful');
} catch (e) {
const timeout = 5000;
// eslint-disable-next-line no-console
console.log(`Connection Error: Retrying in ${timeout}ms`);
setTimeout(() => {
tryConnect();
}, timeout);
} finally {
if (session) await session.close();
if (driver) await driver.close();
}
}

tryConnect();
5 changes: 5 additions & 0 deletions backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==

ecc-jsbn@~0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"
Expand Down
40 changes: 40 additions & 0 deletions build/start-database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Starts the database docker container with the testing dump.
*/

const path = require("path");
const { execSync } = require("child_process");

const containerName="neo4j-db"
const repoPath = path.join(__dirname, "..");
const mountPath = path.join(repoPath, "backend", "docker", "mount");
const pluginsPath = path.join(repoPath, "backend", "docker", "plugins");

async function main() {
try {
execSync(`docker container stop ${containerName}`)
} catch(e) {}

try {
execSync(`docker container rm ${containerName}`)
} catch(e) {}

const command = `
docker run -d -p 7474:7474 -p 7687:7687 \\
-v ${mountPath}:/mnt/amos \\
-v ${pluginsPath}:/plugins \\
--env NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \\
--env DB_PASSWORD=amos \\
--env DB_PATH=/mnt/amos/dumps/testing-dump.dump \\
--env 'NEO4JLABS_PLUGINS=["apoc", "graph-data-science"]' \\
--env 'NEO4J_dbms_security_procedures_unrestricted=apoc.*,gds.*' \\
--env 'NEO4J_dbms_security_procedures_allowlist=apoc.*,gds.*' \\
--env NEO4J_apoc_import_file_enabled=true \\
--name ${containerName} neo4j:4.2-enterprise \\
/mnt/amos/load-dump.sh
`

execSync(command);
}

main();
23 changes: 0 additions & 23 deletions build/start-database.ps1

This file was deleted.

25 changes: 0 additions & 25 deletions build/start-database.sh

This file was deleted.

14 changes: 1 addition & 13 deletions build/workflows/actions/start-db.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
- run: |
docker run -d -p 7474:7474 -p 7687:7687 \
-v ${GITHUB_WORKSPACE}/backend/docker/mount:/mnt/amos \
-v ${GITHUB_WORKSPACE}/backend/docker/plugins:/plugins \
--env NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \
--env DB_PASSWORD=amos \
--env DB_PATH=/mnt/amos/dumps/testing-dump.dump \
--env 'NEO4JLABS_PLUGINS=["apoc", "graph-data-science"]' \
--env 'NEO4J_dbms_security_procedures_unrestricted=apoc.*,gds.*' \
--env 'NEO4J_dbms_security_procedures_allowlist=apoc.*,gds.*' \
--env NEO4J_apoc_import_file_enabled=true \
--name neo4j-DB neo4j:enterprise \
/mnt/amos/load-dump.sh
- run: node build/start-database
15 changes: 6 additions & 9 deletions build/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ jobs:
- run: yarn install --frozen-lockfile --prefer-offline --network-timeout 1000000
working-directory: ${{ env.working-directory }}

- name: Add .env file
run: cp .env.test .env
working-directory: ${{ env.working-directory }}

- name: Wait on DB Server
run: npx wait-on http://localhost:7474
run: node backend/wait-on-db
timeout-minutes: 3

- run: yarn run test:cov
working-directory: ${{ env.working-directory }}
env:
NEO4J_SCHEME: neo4j
NEO4J_HOST: localhost
NEO4J_PORT: 7687
NEO4J_USERNAME: neo4j
NEO4J_PASSWORD: amos
NEO4J_DATABASE: neo4j
CORS_URL: http://localhost:3000
timeout-minutes: 15
8 changes: 4 additions & 4 deletions build/workflows/frontend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ jobs:
- run: yarn install --frozen-lockfile --prefer-offline --network-timeout 1000000
working-directory: ./backend

- name: Wait on DB Server
run: wait-on tcp:7687
timeout-minutes: 3

- name: Start Frontend Dev Server (detached)
run: pm2 start ./build/start-frontend-detached.js

- name: Wait on DB Server
run: node backend/wait-on-db
timeout-minutes: 3
- name: Start Backend Dev Server (detached)
run: pm2 start ./build/start-backend-detached.js

Expand Down
38 changes: 38 additions & 0 deletions frontend/cypress/integration/exploration/exploration.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import layoutsData from '../../../src/exploration/previews/layoutsData';

context('Exploration', () => {
// Global setup
beforeEach(() => {
cy.visit('http://localhost:3000/exploration');
});

context('Previews', () => {
it('lists correct number of previews', () => {
cy.get('.Previews');
cy.get('.LayoutPreview').should('have.length', 7);
});

it('correct initial layouts', () => {
cy.get('.Previews');

const layoutsDataValues = Object.values(layoutsData);
cy.get('.LayoutPreview').each(($el, index) => {
cy.wrap($el).should('have.text', layoutsDataValues[index].description);
});
});

it('routes to graph page', () => {
cy.get('.Previews');
cy.get('.LayoutPreview').eq(0).click();
cy.url().should('eq', `http://localhost:3000${layoutsData.C.path}`);
});

it('routes to hierarchical page', () => {
cy.get('.Previews');
cy.get('.LayoutPreview').eq(2).click();
cy.url().should('eq', `http://localhost:3000${layoutsData.H.path}`);
});

// TODO: add more tests when combined with questions
});
});
44 changes: 44 additions & 0 deletions frontend/cypress/unit/appendQuery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import appendQuery from '../../src/services/http/appendQuery';

describe('appendQuery', () => {
let url: URL;
const baseUrl = 'https://example.com';

beforeEach(() => {
url = new URL(baseUrl);
});

it('should not change input href on empty input', () => {
const actual = appendQuery(url, {});
expect(actual.href).to.be.eq(`${url.href}`);
});

it('should be able to handle strings', () => {
const actual = appendQuery(url, { example: 'successful' });
expect(actual.href).to.be.eq(`${url.href}?example=successful`);
});

it('should be able to handle numbers', () => {
const actual = appendQuery(url, { example: 42 });
expect(actual.href).to.be.eq(`${url.href}?example=42`);
});

it('should be able to handle arrays', () => {
const actual = appendQuery(url, { example: [1, 2, 3] });
expect(actual.href).to.be.eq(`${url.href}?example=1&example=2&example=3`);
});

describe('appending query', () => {
it('should be able to append to given queries', () => {
url = new URL(`${baseUrl}?given=1`);
const actual = appendQuery(url, { example: [1, 2, 3] });
expect(actual.href).to.be.eq(`${url.href}&example=1&example=2&example=3`);
});

it('should be able to append to given empty query', () => {
url = new URL(`${baseUrl}?`);
const actual = appendQuery(url, { example: [1, 2, 3] });
expect(actual.href).to.be.eq(`${url.href}example=1&example=2&example=3`);
});
});
});
Loading

0 comments on commit 3338359

Please sign in to comment.