Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Test #54

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
config.env
coverage/
3 changes: 0 additions & 3 deletions client/app/NotesItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ export default class NotesItem extends Component{
render(){
const formatTime = time => new Date(time * 1000).toISOString().substr(11, 8);
return (

<div className="eachNotes">
<h4>{this.props.content}</h4>
{this.props.timestamp !== undefined &&
<p onClick={this.goto}>{formatTime(this.props.timestamp)}</p>}
<button id="edit">Edit</button>
<button id="delete">delete</button>
</div>


)
}
}
4 changes: 0 additions & 4 deletions client/app/NotesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export default class NotesList extends Component{
headers: {'Content-Type':'application/x-www-form-urlencoded'}, //no idea why this work but fuck this
body: `video_id=${videoId}&text=${notes}&timestamp=${currentTime}`
})
.then(res => res.json(res))
.then(res => console.log('from db for notes',res))
.catch(err => console.log(err));

// console.log(currentTime, videoId, notes);
}
e.target.reset();
}
Expand Down
7 changes: 3 additions & 4 deletions client/app/URLInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ class URLInput extends Component{
const videoID = this.url.value.split('=')[1].substr(0,11);
//need to check userinput nvm that for now
event.preventDefault();

this.props.onInputChange({thumbnail: `https://img.youtube.com/vi/${videoID}/sddefault.jpg`});

fetch('/add',
{
method: 'POST',
headers: {'Content-Type':'application/x-www-form-urlencoded'}, //no idea why this work but fuck this
body: `url=${videoID}`
})
.then(res => res.json(res))
.then(res =>
this.props.onInputChange({thumbnail: `https://img.youtube.com/vi/${videoID}/sddefault.jpg`})
)
.catch(err => console.log(err));

this.form.reset();
Expand Down
6 changes: 3 additions & 3 deletions client/public/bundle.js

Large diffs are not rendered by default.

66 changes: 42 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "webpack -d --watch",
"build": "webpack -p",
"start": "node server/server.js",
"test": "jest"
"test": "jest --coverage"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,7 +39,8 @@
"babel-preset-react": "^6.24.1",
"enzyme": "^2.9.1",
"jest": "^21.1.0",
"react-test-render": "^1.0.3",
"react-test-renderer": "^15.6.1",
"supertest": "^3.0.0",
"webpack": "^3.5.6"
}
}
41 changes: 41 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const express = require('express'),
app = express(),
path = require('path'),
bp = require('body-parser'),
{addVideo, getGallery, getNotes, addNotes} = require('./query/queries');


app.use(express.static(path.join(__dirname, '..', 'client', 'public')));


app.use(bp.urlencoded({extended: true}));

app.get('/getGallery', (req, resp) => {
getGallery()
.then(res => resp.send(res))
.catch(err => console.log(err));
});

app.post('/getnotes', (req, resp)=>{
getNotes(req.body.video_id)
.then(res => resp.send(res))
.catch(err => console.log(err));
});

app.post('/addnotes', (req, resp)=>{
addNotes(req.body.timestamp, req.body.text, req.body.video_id)
.then(res => console.log('successfully added notes'))
.catch(err => console.log(err));
});

app.post('/add', (req, resp)=>{
addVideo(req.body.url)
.then(res => console.log('successfully added video'))
.catch(err => console.log(err));
});

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

module.exports = app;
42 changes: 1 addition & 41 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
const express = require('express'),
app = express(),
path = require('path'),
bp = require('body-parser'),
{addVideo, getGallery, getNotes, addNotes} = require('./query/queries'),
const app = require('./app'),
PORT = process.env.PORT || 9001;

app.use(express.static(path.join(__dirname, '..', 'client', 'public')));


app.use(bp.urlencoded({extended: true}));

app.get('/getGallery', (req, resp) => {
console.log('hit get gallery');
getGallery()
.then(res => resp.send(res))
.catch(err => console.log(err));
});

app.post('/getnotes', (req, resp)=>{
console.log('hit get notes');
getNotes(req.body.video_id)
.then(res => resp.send(res))
.catch(err => console.log(err));
});

app.post('/addnotes', (req, res)=>{
addNotes(req.body.timestamp, req.body.text, req.body.video_id)
.then(res => resp.send(res))
.catch(err => console.log(err));
});

app.post('/add', (req, res)=>{
addVideo(req.body.url)
.then(res => console.log(res))
.catch(err => console.log(err));
res.send(req.body); //for debugging
});

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

app.listen(PORT, ()=>{
console.log(`magic is happening in http://localhost:${PORT}`);
});
6 changes: 6 additions & 0 deletions test/NotesItem.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import NotesItem from '../client/app/NotesItem';
import React from 'react';
import renderer from 'react-test-renderer';
import {shallow} from 'enzyme';

test();
46 changes: 46 additions & 0 deletions test/route.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const app = require('../server/app'),
request = require('supertest');

describe('Test catch all path', () => {
//using done
test('It should response the GET method', done => {
request(app).get('/').then((response) => {
expect(response.statusCode).toBe(200);
done();
});
});
//using return
test('It should return the html', ()=>{
return request(app).get('/').then((response) => {
expect(response.text).toMatch(/<html>/);
});
});

test('Check type of return', ()=>{
return request(app).get('/').then((response) => {
expect(response.header['content-type']).toMatch(/text\/html/);
});
});
});
//TBC
// describe('Test /add route', () => {
// //using done
// test('It should response the GET method', done => {
// request(app).post('/').then((response) => {
// expect(response.statusCode).toBe(200);
// done();
// });
// });
// //using return
// test('It should return the html', ()=>{
// return request(app).get('/').then((response) => {
// expect(response.text).toMatch(/<html>/);
// });
// });
//
// test('Check type of return', ()=>{
// return request(app).get('/').then((response) => {
// expect(response.header['content-type']).toMatch(/text\/html/);
// });
// });
// });
Empty file removed test/test.js
Empty file.