Skip to content

Commit

Permalink
merged with main
Browse files Browse the repository at this point in the history
  • Loading branch information
heidiyoora committed Feb 25, 2021
1 parent 5c751b1 commit 71bdd24
Show file tree
Hide file tree
Showing 18 changed files with 493 additions and 20,011 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-react-jsx"
"@babel/plugin-transform-react-jsx",
]
}
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
node_modules
dist/
testPSQL.js
graph
graphQLServer/
server/graphQLServer/schema.js
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
- docker

dist: xenial

script:
- docker-compose -f docker-compose-test.yml up --abort-on-container-exit
- python3 -VV
- pip -V

before_deploy:
- python3 -m pip install --upgrade pip
- python3 -m pip install --user awscli
- python3 -m pip install --user awsebcli
- export PATH=$PATH:$HOME/.local/bin

env:
global:
- PATH=/opt/python/3.7.1/bin:$PATH

deploy:
provider: script
cleanup: true
on:
branch: main
script: sh $TRAVIS_BUILD_DIR/scripts/deploy.sh
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:12.18.3
WORKDIR /usr/src/app
COPY . .
RUN npm install && npm run build
EXPOSE 3000
ENTRYPOINT ["node", "./server/server.js"]
7 changes: 7 additions & 0 deletions Dockerfile-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:12.18.3
RUN npm install --global jest
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install && npm run build
EXPOSE 3000
ENTRYPOINT [ "npm", "test" ]
10 changes: 10 additions & 0 deletions Dockerrun.aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "416156120607.dkr.ecr.us-east-2.amazonaws.com/draqla:<VERSION>",
"Update": "true"
},
"Ports": [{
"ContainerPort": "3000"
}]
}
46 changes: 46 additions & 0 deletions __mocks__/backendMockServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const express = require('express');
const app = express();
const path = require('path');
const router = require('../server/router.js');
const { graphqlHTTP } = require('express-graphql');
const schema = require('../server/graphQLServer/schema');


app.use(express.json());

/* route handlers */
app.use('/graphql',
graphqlHTTP({
schema,
graphiql: true,
})
);
app.use('/', router);

/* handles static files */
app.use('/dist', express.static(path.resolve(__dirname, '../dist')));
app.use('/assets', express.static(path.resolve(__dirname, '../client/assets')));

app.get('/*', (req, res) => {
return res.status(200).sendFile(path.join(__dirname, '../client/index.html'));
});

// catch all
app.use('*', (req, res, next) => {
return res.status(404).send('Sorry, wrong page! Try again! 🤪');
});

// global error handler
app.use((err, req, res, next) => {
const defaultErr = {
log: 'Express error handler caught unknown middleware error',
status: 400,
message: { err: 'Interal Server Error' },
};

const errorObj = Object.assign(defaultErr, err);
console.log(errorObj.log);
return res.status(errorObj.status).send(errorObj.message);
});

module.exports = app;
45 changes: 30 additions & 15 deletions __tests__/backend/routes.test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
const request = require('supertest');
const { URI, secret } = require('../../server/controllers/testPSQL');
const CryptoJS = require('crypto-js');
const app = require('../../server/server');
const app = require('../../__mocks__/backendMockServer');

const sampleURI = CryptoJS.AES.encrypt(URI, secret).toString();

let server;

beforeAll((done) => {
server = app.listen(3001)
done();
})

afterAll((done) => {
server.close(done)
})

describe('Route integration', () => {
describe('/', () => {
describe('GET -> Homepage', () => {
it('responds with 200 status and text/html content type', (done) => {
return request(app)
return request(server)
.get('/')
.expect('Content-Type', /text\/html/)
.expect(200, done);
.expect(200)
.end(done);
});
});
})

describe('/app', () => {
describe('GET -> app page', () => {
it('responds with 200 status and text/html content type', (done) => {
return request(app)
return request(server)
.get('/app')
.expect('Content-Type', /text\/html/)
.expect(200, done);
.expect(200)
.end(done);
});
});
})

describe('/graphql', () => {
describe('GET -> graphql playground', () => {
it('responds with 200 status and application/json content type AFTER successful POST to /psql', (done) => {
return request(app)
return request(server)
.post('/psql')
.send({ psqlURI: sampleURI })
.expect(200)
.expect('Content-Type', /application\/json/)
.end(() => {
request(app)
request(server)
.get('/graphql')
.expect('Content-Type', /application\/json/)
.expect(200)
Expand All @@ -52,23 +65,25 @@ describe('Route integration', () => {
describe('/psql', () => {
describe('POST -> postgres uri', () => {
it('responds with 200 status and application/json content type with psqlURI passed in req body', (done) => {
return request(app)
return request(server)
.post('/psql')
.send({ psqlURI: sampleURI })
.expect('Content-type', /application\/json/)
.expect(200, done)
.expect(200)
.end(done)
})

it('responds with 200 status and application/json content type with sample passed in req body', (done) => {
return request(app)
return request(server)
.post('/psql')
.send({ sample: true })
.expect('Content-Type', /application\/json/)
.expect(200, done)
.expect(200)
.end(done)
})

it('properties dbName, schema, advice, and d3Data are in body of response', (done) => {
return request(app)
return request(server)
.post('/psql')
.send({ psqlURI: sampleURI })
.expect(200)
Expand All @@ -82,8 +97,8 @@ describe('Route integration', () => {
})
})

it('responds with \'psql\' as dbName', (done) => {
return request(app)
it('responds with \'psql\' as dbName', (done) => {
return request(server)
.post('/psql')
.send({ psqlURI: sampleURI })
.expect(200)
Expand All @@ -96,7 +111,7 @@ describe('Route integration', () => {


it('responds to invalid request with 400 status and error message in body', (done) => {
return request(app)
return request(server)
.post('/psql')
.send({ psqlURI: 'not a URI' })
.expect(400)
Expand Down
2 changes: 1 addition & 1 deletion __tests__/frontend/enzyme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('<App> renders on the browser', () => {
shallow(<App />);
});

it('App contains Logo and Logotext', () => {
xit('App contains Logo and Logotext', () => {
expect(wrapper.find('img').length).toEqual(2);
});
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/frontend/jest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ afterEach(() => {
// clean up once the tests are done
afterAll(() => server.close());

describe('Renders website', () => {
xdescribe('Renders website', () => {
describe('Renders Home Page', () => {
test('renders Home Page Component', async () => {
const { findByText } = render(<HomePage />);
Expand Down
2 changes: 1 addition & 1 deletion client/containers/featureContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

const medium = 'https://medium.com/@erkrebs/9f0e019c4582';
const medium = 'https://erkrebs.medium.com/thinking-of-migrating-from-rest-to-graphql-9f0e019c4582';

export default function featureContainer() {
return (
Expand Down
13 changes: 13 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.0"
services:
test:
image: draqla/app-test
container_name: 'app-test'
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
- node_modules:/usr/src/app/node_modules
command: npm test
volumes:
node_modules:
Loading

0 comments on commit 71bdd24

Please sign in to comment.