Skip to content

Commit ca0d7c7

Browse files
authored
Merge pull request #417 from LD4P/retrieve_rt_from_server_309
Prepare to retrieve resource templates from Sinopia platform
2 parents 6feac83 + 21c9674 commit ca0d7c7

16 files changed

+218
-166
lines changed

.eslintrc.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ module.exports = {
4848
overrides: [
4949
{
5050
"files": ["**/*.jsx",
51-
"src/index.js",
52-
"src/*/*.js",
53-
"src/store.js",
54-
"src/Config.js",
55-
"src/LoginData.js",
56-
"src/Logout.js",
57-
"src/localStorage.js"],
51+
"src/**/*.js",
52+
"__tests__/**/*.js",
53+
"__mocks__/**/*.js"],
5854
"rules": {
5955
// See https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-unsupported-features/es-syntax.md
6056
// rule supposedly matches ECMA version with node

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM node:10.11
1+
FROM circleci/node:10.11
2+
23
WORKDIR /opt/sinopia_editor/
34

45
# Everything that isn't in .dockerignore ships

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The Sinopia Editor code is currently available via [sinopia.io](https://sinopia.
3838

3939
`npm run dev-start`
4040

41-
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).
41+
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).
4242
Note that running the webpack server does NOT call server.js
4343

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

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

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

7070
### Test
7171

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

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

165165
#### User Authentication with AWS Cognito
166166

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

173173
Acknowledgements
@@ -227,7 +227,7 @@ License
227227
-------
228228

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

232232
Original `bfe` code is in the Public Domain.
233233

__tests__/integration/landingPage.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Copyright 2018 Stanford University see Apache2.txt for license
22
import expect from 'expect-puppeteer'
33

4-
54
describe('Basic end to end Sinopia Linked Data Editor', () => {
6-
75
beforeAll(async () => {
8-
await page.goto('http://127.0.0.1:8080/');
6+
jest.setTimeout(15000);
7+
await page.goto('http://127.0.0.1:8888/');
98
});
109

11-
it('displays "Linked Data Editor" and "Profile Editor" in menu', async () => {
10+
it('displays "Linked Data Editor" and "Profile Editor" in menu', async () => {
1211
await expect(page).toMatch('Linked Data Editor')
1312
await expect(page).toMatch('Profile Editor')
1413
});

__tests__/integration/schemaValidation.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import Config from '../../src/Config'
44

55
describe('Editor', () => {
66
beforeAll(async () => {
7-
await page.goto(`http://127.0.0.1:8080/${Config.awsCognitoJWTHashForTest}`)
7+
jest.setTimeout(15000);
8+
await page.goto(`http://127.0.0.1:8888/${Config.awsCognitoJWTHashForTest}`)
89
})
910

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

1819
describe('schema valid', () => {
1920
beforeEach(async () => {
20-
await page.goto('http://127.0.0.1:8080/import')
21+
await page.goto('http://127.0.0.1:8888/import')
2122
})
2223

2324
describe('schema url in JSON', () => {
@@ -84,7 +85,7 @@ describe('Editor', () => {
8485
describe('not schema valid', () => {
8586
let dialog
8687
beforeAll(async() => {
87-
await page.goto('http://127.0.0.1:8080/import')
88+
await page.goto('http://127.0.0.1:8888/import')
8889
await page.waitForSelector('button#ImportProfile')
8990
await page.click('button#ImportProfile')
9091
await pupExpect(page).toMatch('select a file to upload:')

__tests__/sinopiaServer.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
describe('sinopiaServerSpoof', () => {
2+
let sinopiaServer = require('../src/sinopiaServer')
3+
4+
describe('resourceTemplateIds', () => {
5+
it('array of length 19', () => {
6+
expect(sinopiaServer.resourceTemplateIds).toHaveLength(19)
7+
})
8+
it('resourceTemplateId is in expected format', () => {
9+
sinopiaServer.resourceTemplateIds.forEach(id => {
10+
expect(id).toMatch(/^resourceTemplate:((bf2)|(bflc)):.*/)
11+
})
12+
})
13+
})
14+
15+
describe('resourceTemplateId2Json', () => {
16+
it('array of length 19', () => {
17+
expect(sinopiaServer.resourceTemplateId2Json).toHaveLength(19)
18+
})
19+
it('mapping has id', () => {
20+
expect(sinopiaServer.resourceTemplateId2Json[0]['id']).toBe('resourceTemplate:bf2:Monograph:Instance')
21+
expect(sinopiaServer.resourceTemplateId2Json[10]['id']).toBe('resourceTemplate:bf2:WorkVariantTitle')
22+
})
23+
it('mapping has json', () => {
24+
expect(sinopiaServer.resourceTemplateId2Json[0]['json']).toBeDefined()
25+
expect(sinopiaServer.resourceTemplateId2Json[10]['json']).toBeDefined()
26+
})
27+
})
28+
29+
describe('getResourceTemplate', () => {
30+
it('known id: returns JSON for resource template', () => {
31+
expect(sinopiaServer.getResourceTemplate('resourceTemplate:bf2:Title').id).toEqual('resourceTemplate:bf2:Title')
32+
expect(sinopiaServer.getResourceTemplate('resourceTemplate:bf2:Title').resourceLabel).toEqual('Instance Title')
33+
})
34+
it('unknown id: returns empty resource template and logs error', () => {
35+
let output = ''
36+
let storeErr = inputs => (output += inputs)
37+
console["log"] = jest.fn(storeErr)
38+
expect(sinopiaServer.getResourceTemplate('not:there')).toEqual({"propertyTemplates": [{}]})
39+
expect(output).toEqual('ERROR: un-spoofed resourceTemplate: not:there')
40+
})
41+
it('null id: returns empty resource template and logs error', () => {
42+
let output = ''
43+
let storeErr = inputs => (output += inputs)
44+
console["log"] = jest.fn(storeErr)
45+
expect(sinopiaServer.getResourceTemplate()).toEqual({"propertyTemplates": [{}]})
46+
expect(output).toEqual('ERROR: asked for resourceTemplate with null/undefined id')
47+
output = ''
48+
expect(sinopiaServer.getResourceTemplate(null)).toEqual({"propertyTemplates": [{}]})
49+
expect(output).toEqual('ERROR: asked for resourceTemplate with null/undefined id')
50+
output = ''
51+
expect(sinopiaServer.getResourceTemplate(undefined)).toEqual({"propertyTemplates": [{}]})
52+
expect(output).toEqual('ERROR: asked for resourceTemplate with null/undefined id')
53+
expect(sinopiaServer.getResourceTemplate('')).toEqual({"propertyTemplates": [{}]})
54+
})
55+
56+
})
57+
})

__tests__/sinopiaServerSpoof.test.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

docker-compose.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
version: "3"
2+
services:
3+
editor:
4+
build:
5+
context: .
6+
ports:
7+
- 8000:8000
8+
depends_on:
9+
- pipeline
10+
pipeline:
11+
image: ld4p/sinopia_indexing_pipeline:latest
12+
environment:
13+
INDEX_HOST: search
14+
BROKER_HOST: broker
15+
command: dockerize -wait tcp://broker:61613 -wait tcp://search:9200 -timeout 3m npm start
16+
depends_on:
17+
- broker
18+
- search
19+
- platform
20+
broker:
21+
image: rmohr/activemq
22+
ports:
23+
- 61613:61613
24+
platform:
25+
image: ld4p/trellis-ext-db:latest
26+
environment:
27+
TRELLIS_BASE_URL: http://platform:8080
28+
TRELLIS_LOGGING_LEVEL: INFO
29+
TRELLIS_CONSOLE_LOGGING_THRESHOLD: INFO
30+
ports:
31+
- 8080:8080
32+
- 8081:8081
33+
depends_on:
34+
- database
35+
- broker
36+
- migration
37+
database:
38+
image: postgres:latest
39+
environment:
40+
POSTGRES_USER: sinopia
41+
POSTGRES_DB: sinopia
42+
POSTGRES_PASSWORD: S1n0p1a
43+
PGDATA: /var/lib/postgresql/data/pgdata/mydata
44+
ports:
45+
- 5432:5432
46+
search:
47+
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
48+
entrypoint:
49+
- elasticsearch
50+
- -Ehttp.port=9200
51+
- -Ehttp.cors.enabled=true
52+
- -Ehttp.cors.allow-origin=http://searchui:1358,http://localhost:1358,http://127.0.0.1:1358
53+
- -Ehttp.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
54+
- -Ehttp.cors.allow-credentials=true
55+
- -Etransport.host=localhost
56+
- -Ebootstrap.system_call_filter=false
57+
user: elasticsearch
58+
ports:
59+
- 9200:9200
60+
- 9300:9300
61+
searchui:
62+
image: appbaseio/dejavu:latest
63+
ports:
64+
- 1358:1358
65+
depends_on:
66+
- search
67+
migration:
68+
image: ld4p/trellis-ext-db:latest
69+
command: ["/opt/trellis/bin/trellis-db", "db", "migrate", "/opt/trellis/etc/config.yml"]
70+
depends_on:
71+
- database

jest-puppeteer.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module.exports = {
77
},
88
server: {
99
command: 'npm run dev-start',
10-
port: 8080,
10+
port: 8888
1111
},
1212
};

src/components/editor/PropertyTemplateOutline.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import InputLiteral from './InputLiteral'
55
import OutlineHeader from './OutlineHeader'
66
import PropertyTypeRow from './PropertyTypeRow'
77
import RequiredSuperscript from './RequiredSuperscript'
8-
const { getResourceTemplate } = require('../../sinopiaServerSpoof.js')
8+
import { getResourceTemplate } from '../../sinopiaServer'
99
import PropTypes from 'prop-types'
1010
import shortid from 'shortid'
1111

0 commit comments

Comments
 (0)