Skip to content

Commit

Permalink
Merge pull request #417 from LD4P/retrieve_rt_from_server_309
Browse files Browse the repository at this point in the history
Prepare to retrieve resource templates from Sinopia platform
  • Loading branch information
jgreben authored Mar 14, 2019
2 parents 6feac83 + 21c9674 commit ca0d7c7
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 166 deletions.
10 changes: 3 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ module.exports = {
overrides: [
{
"files": ["**/*.jsx",
"src/index.js",
"src/*/*.js",
"src/store.js",
"src/Config.js",
"src/LoginData.js",
"src/Logout.js",
"src/localStorage.js"],
"src/**/*.js",
"__tests__/**/*.js",
"__mocks__/**/*.js"],
"rules": {
// See https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-unsupported-features/es-syntax.md
// rule supposedly matches ECMA version with node
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM node:10.11
FROM circleci/node:10.11

WORKDIR /opt/sinopia_editor/

# Everything that isn't in .dockerignore ships
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The Sinopia Editor code is currently available via [sinopia.io](https://sinopia.

`npm run dev-start`

Runs the webpack-dev-server, allowing immediate loading of live code changes without having to restart the server. The webpack-dev-server is available on at [http://localhost:8080](http://localhost:8080).
Runs the webpack-dev-server, allowing immediate loading of live code changes without having to restart the server. The webpack-dev-server is available on at [http://localhost:8888](http://localhost:8888).
Note that running the webpack server does NOT call server.js

### Building with webpack
Expand All @@ -50,7 +50,7 @@ We are using webpack as a build tool. See `webpack.config.js` for build depende
##### Running the server with express directory

`npm start` will spin up express directly.
The express server is available on at [http://localhost:8000](http://localhost:8000).
The express server is available on at [http://localhost:8000](http://localhost:8000).

>>>>>>> Update README and remove references to grunt
### Linter for JavaScript
Expand All @@ -69,7 +69,7 @@ See https://www.npmjs.com/package/eslint-takeoff for more info.

### Test

Tests are written in jest, also utilizing puppeteer for end-to-end tests.
Tests are written in jest, also utilizing puppeteer for end-to-end tests.
To run them `npm test`.

#### Test coverage
Expand Down Expand Up @@ -164,10 +164,10 @@ All contributions are welcome. If you do not code, surely you will discover an

#### User Authentication with AWS Cognito

We currently use AWS Cognito to manage the authentication of users. Cognito uses a client id to manage the connection to
this application (see `awsClientID()` in `src/Config.js`). Whenever changes are made to the AWS configuration this client_id
changes and so you must also submit a PR to change the client id in this application as well. In the production environment
this will be handled via an environment variable, but for local functionality and testing, the hard-coded value must be updated,
We currently use AWS Cognito to manage the authentication of users. Cognito uses a client id to manage the connection to
this application (see `awsClientID()` in `src/Config.js`). Whenever changes are made to the AWS configuration this client_id
changes and so you must also submit a PR to change the client id in this application as well. In the production environment
this will be handled via an environment variable, but for local functionality and testing, the hard-coded value must be updated,
or you must set the environment variable `AWS_CLIENT_ID` to be the current client id.

Acknowledgements
Expand Down Expand Up @@ -227,7 +227,7 @@ License
-------

Unless otherwise noted, code that is originally developed by Stanford University
in the `Sinopia Editor` is licensed under the [Apache 2](https://www.apache.org/licenses/LICENSE-2.0).
in the `Sinopia Editor` is licensed under the [Apache 2](https://www.apache.org/licenses/LICENSE-2.0).

Original `bfe` code is in the Public Domain.

Expand Down
7 changes: 3 additions & 4 deletions __tests__/integration/landingPage.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright 2018 Stanford University see Apache2.txt for license
import expect from 'expect-puppeteer'


describe('Basic end to end Sinopia Linked Data Editor', () => {

beforeAll(async () => {
await page.goto('http://127.0.0.1:8080/');
jest.setTimeout(15000);
await page.goto('http://127.0.0.1:8888/');
});

it('displays "Linked Data Editor" and "Profile Editor" in menu', async () => {
it('displays "Linked Data Editor" and "Profile Editor" in menu', async () => {
await expect(page).toMatch('Linked Data Editor')
await expect(page).toMatch('Profile Editor')
});
Expand Down
7 changes: 4 additions & 3 deletions __tests__/integration/schemaValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Config from '../../src/Config'

describe('Editor', () => {
beforeAll(async () => {
await page.goto(`http://127.0.0.1:8080/${Config.awsCognitoJWTHashForTest}`)
jest.setTimeout(15000);
await page.goto(`http://127.0.0.1:8888/${Config.awsCognitoJWTHashForTest}`)
})

describe('importing a profile/template', () => {
Expand All @@ -17,7 +18,7 @@ describe('Editor', () => {

describe('schema valid', () => {
beforeEach(async () => {
await page.goto('http://127.0.0.1:8080/import')
await page.goto('http://127.0.0.1:8888/import')
})

describe('schema url in JSON', () => {
Expand Down Expand Up @@ -84,7 +85,7 @@ describe('Editor', () => {
describe('not schema valid', () => {
let dialog
beforeAll(async() => {
await page.goto('http://127.0.0.1:8080/import')
await page.goto('http://127.0.0.1:8888/import')
await page.waitForSelector('button#ImportProfile')
await page.click('button#ImportProfile')
await pupExpect(page).toMatch('select a file to upload:')
Expand Down
57 changes: 57 additions & 0 deletions __tests__/sinopiaServer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
describe('sinopiaServerSpoof', () => {
let sinopiaServer = require('../src/sinopiaServer')

describe('resourceTemplateIds', () => {
it('array of length 19', () => {
expect(sinopiaServer.resourceTemplateIds).toHaveLength(19)
})
it('resourceTemplateId is in expected format', () => {
sinopiaServer.resourceTemplateIds.forEach(id => {
expect(id).toMatch(/^resourceTemplate:((bf2)|(bflc)):.*/)
})
})
})

describe('resourceTemplateId2Json', () => {
it('array of length 19', () => {
expect(sinopiaServer.resourceTemplateId2Json).toHaveLength(19)
})
it('mapping has id', () => {
expect(sinopiaServer.resourceTemplateId2Json[0]['id']).toBe('resourceTemplate:bf2:Monograph:Instance')
expect(sinopiaServer.resourceTemplateId2Json[10]['id']).toBe('resourceTemplate:bf2:WorkVariantTitle')
})
it('mapping has json', () => {
expect(sinopiaServer.resourceTemplateId2Json[0]['json']).toBeDefined()
expect(sinopiaServer.resourceTemplateId2Json[10]['json']).toBeDefined()
})
})

describe('getResourceTemplate', () => {
it('known id: returns JSON for resource template', () => {
expect(sinopiaServer.getResourceTemplate('resourceTemplate:bf2:Title').id).toEqual('resourceTemplate:bf2:Title')
expect(sinopiaServer.getResourceTemplate('resourceTemplate:bf2:Title').resourceLabel).toEqual('Instance Title')
})
it('unknown id: returns empty resource template and logs error', () => {
let output = ''
let storeErr = inputs => (output += inputs)
console["log"] = jest.fn(storeErr)
expect(sinopiaServer.getResourceTemplate('not:there')).toEqual({"propertyTemplates": [{}]})
expect(output).toEqual('ERROR: un-spoofed resourceTemplate: not:there')
})
it('null id: returns empty resource template and logs error', () => {
let output = ''
let storeErr = inputs => (output += inputs)
console["log"] = jest.fn(storeErr)
expect(sinopiaServer.getResourceTemplate()).toEqual({"propertyTemplates": [{}]})
expect(output).toEqual('ERROR: asked for resourceTemplate with null/undefined id')
output = ''
expect(sinopiaServer.getResourceTemplate(null)).toEqual({"propertyTemplates": [{}]})
expect(output).toEqual('ERROR: asked for resourceTemplate with null/undefined id')
output = ''
expect(sinopiaServer.getResourceTemplate(undefined)).toEqual({"propertyTemplates": [{}]})
expect(output).toEqual('ERROR: asked for resourceTemplate with null/undefined id')
expect(sinopiaServer.getResourceTemplate('')).toEqual({"propertyTemplates": [{}]})
})

})
})
57 changes: 0 additions & 57 deletions __tests__/sinopiaServerSpoof.test.js

This file was deleted.

71 changes: 71 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
version: "3"
services:
editor:
build:
context: .
ports:
- 8000:8000
depends_on:
- pipeline
pipeline:
image: ld4p/sinopia_indexing_pipeline:latest
environment:
INDEX_HOST: search
BROKER_HOST: broker
command: dockerize -wait tcp://broker:61613 -wait tcp://search:9200 -timeout 3m npm start
depends_on:
- broker
- search
- platform
broker:
image: rmohr/activemq
ports:
- 61613:61613
platform:
image: ld4p/trellis-ext-db:latest
environment:
TRELLIS_BASE_URL: http://platform:8080
TRELLIS_LOGGING_LEVEL: INFO
TRELLIS_CONSOLE_LOGGING_THRESHOLD: INFO
ports:
- 8080:8080
- 8081:8081
depends_on:
- database
- broker
- migration
database:
image: postgres:latest
environment:
POSTGRES_USER: sinopia
POSTGRES_DB: sinopia
POSTGRES_PASSWORD: S1n0p1a
PGDATA: /var/lib/postgresql/data/pgdata/mydata
ports:
- 5432:5432
search:
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
entrypoint:
- elasticsearch
- -Ehttp.port=9200
- -Ehttp.cors.enabled=true
- -Ehttp.cors.allow-origin=http://searchui:1358,http://localhost:1358,http://127.0.0.1:1358
- -Ehttp.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
- -Ehttp.cors.allow-credentials=true
- -Etransport.host=localhost
- -Ebootstrap.system_call_filter=false
user: elasticsearch
ports:
- 9200:9200
- 9300:9300
searchui:
image: appbaseio/dejavu:latest
ports:
- 1358:1358
depends_on:
- search
migration:
image: ld4p/trellis-ext-db:latest
command: ["/opt/trellis/bin/trellis-db", "db", "migrate", "/opt/trellis/etc/config.yml"]
depends_on:
- database
2 changes: 1 addition & 1 deletion jest-puppeteer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {
},
server: {
command: 'npm run dev-start',
port: 8080,
port: 8888
},
};
2 changes: 1 addition & 1 deletion src/components/editor/PropertyTemplateOutline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InputLiteral from './InputLiteral'
import OutlineHeader from './OutlineHeader'
import PropertyTypeRow from './PropertyTypeRow'
import RequiredSuperscript from './RequiredSuperscript'
const { getResourceTemplate } = require('../../sinopiaServerSpoof.js')
import { getResourceTemplate } from '../../sinopiaServer'
import PropTypes from 'prop-types'
import shortid from 'shortid'

Expand Down
2 changes: 1 addition & 1 deletion src/components/editor/ResourceTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { Component } from 'react'
import { connect } from 'react-redux'
import ResourceTemplateForm from './ResourceTemplateForm'
import { setResourceTemplate } from '../../actions/index'
const { getResourceTemplate } = require('../../sinopiaServerSpoof.js')
import { getResourceTemplate } from '../../sinopiaServer'
import PropTypes from 'prop-types'

class ResourceTemplate extends Component {
Expand Down
2 changes: 1 addition & 1 deletion src/components/editor/ResourceTemplateForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PropertyPanel from './PropertyPanel'
import PropertyResourceTemplate from './PropertyResourceTemplate'
import lookupConfig from '../../../static/spoofedFilesFromServer/fromSinopiaServer/lookupConfig.json'
import {getLD, setItems, removeAllContent} from '../../actions/index'
const { getResourceTemplate } = require('../../sinopiaServerSpoof.js')
import { getResourceTemplate } from '../../sinopiaServer'
const N3 = require('n3')
const { DataFactory } = N3
const { blankNode } = DataFactory
Expand Down
5 changes: 2 additions & 3 deletions src/reducers/linkedData.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//TODO: Replace this resource template call to Trellis
const { getResourceTemplate } = require('../sinopiaServerSpoof.js')
import { getResourceTemplate } from '../sinopiaServer'

const DEFAULT_STATE = {
generateLD: {}
Expand Down Expand Up @@ -133,4 +132,4 @@ const generateLD = (state=DEFAULT_STATE, action) => {
}
}

export { generateLD }
export { generateLD }
Loading

0 comments on commit ca0d7c7

Please sign in to comment.