diff --git a/.gitignore b/.gitignore index 8a0f9f5..deae99c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules -public/bundles.js \ No newline at end of file +public/bundles.js +/coverage.data +/coverage/ \ No newline at end of file diff --git a/client/components/App.jsx b/client/components/App.jsx index f912d88..fe435f3 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -1,17 +1,54 @@ import React, { Component } from 'react'; +import axios from 'axios'; + +import Header from './Header'; +import RatingsList from './RatingsList'; +import ReviewsList from './ReviewsList'; +import Pagination from './Pagination'; class App extends Component { constructor(props) { super(props); this.state = { - message: 'Howdy', + rating: {}, + reviews: [], + reviewGroup: 0, }; + this.updateReviewGroup = this.updateReviewGroup.bind(this); + } + + componentDidMount() { + axios.get('/api/reviews/0/') + .then((res) => this.setState(res.data)) + .catch(console.log); + } + + componentDidUpdate(prevProps, prevState) { + const { reviewGroup } = this.state; + if (prevState.reviewGroup !== reviewGroup) { + axios.get(`/api/reviews/0/?reviewgroup=${reviewGroup}`) + .then((res) => this.setState({ + reviews: res.data.reviews, + })) + .catch(console.log); + } + } + + updateReviewGroup(newReviewGroup) { + this.setState({ + reviewGroup: newReviewGroup, + }); } render() { - const { message } = this.state; + const { rating, reviews, reviewGroup } = this.state; return ( -
{review.author}
+{convertedDate}
++ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 | + + + +1x +1x + + + + + +1x +1x + + + + + + | import React, { Component } from 'react';
+
+class Review extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ message: 'Howdy',
+ };
+ }
+
+ render() {
+ const { message } = this.state;
+ return (
+ <h1>{message}</h1>
+ );
+ }
+}
+export default Review;
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| App.jsx | +
+
+ |
+ 83.33% | +5/6 | +100% | +0/0 | +75% | +3/4 | +83.33% | +5/6 | +
| Header.jsx | +
+
+ |
+ 33.33% | +1/3 | +100% | +0/0 | +0% | +0/1 | +33.33% | +1/3 | +
| RatingsList.jsx | +
+
+ |
+ 25% | +1/4 | +100% | +0/0 | +0% | +0/2 | +25% | +1/4 | +
| RatingsListItem.jsx | +
+
+ |
+ 33.33% | +1/3 | +100% | +0/0 | +0% | +0/1 | +33.33% | +1/3 | +
| ReviewsList.jsx | +
+
+ |
+ 25% | +1/4 | +100% | +0/0 | +0% | +0/2 | +25% | +1/4 | +
| ReviewsListItem.jsx | +
+
+ |
+ 33.33% | +1/3 | +100% | +0/0 | +0% | +0/1 | +33.33% | +1/3 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 | 1x + +1x + + + + + + + + + + + + +1x + + + + + + + +1x +1x + +1x + + + + | const mongoose = require('mongoose');
+
+const roomSchema = new mongoose.Schema({
+ id: Number,
+ rating: {
+ overall: { type: Number, min: 1, max: 5 },
+ accuracy: { type: Number, min: 1, max: 5 },
+ location: { type: Number, min: 1, max: 5 },
+ cleanliness: { type: Number, min: 1, max: 5 },
+ communication: { type: Number, min: 1, max: 5 },
+ checkIn: { type: Number, min: 1, max: 5 },
+ value: { type: Number, min: 1, max: 5 },
+ },
+});
+
+const reviewSchema = new mongoose.Schema({
+ roomid: Number,
+ author: String,
+ authorsAvatar: String,
+ createdAt: Date,
+ text: String,
+});
+
+const Room = mongoose.model('room', roomSchema);
+const Review = mongoose.model('review', reviewSchema);
+
+module.exports = {
+ Room,
+ Review,
+};
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| RoomAndReview.js | +
+
+ |
+ 100% | +6/6 | +100% | +0/0 | +100% | +0/0 | +100% | +6/6 | +
| util.js | +
+
+ |
+ 100% | +27/27 | +100% | +0/0 | +100% | +3/3 | +100% | +24/24 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 | 1x + +1x + +1x + + + + + + + + +1x + +1x + | const mongoose = require('mongoose');
+
+const mongoUri = 'mongodb://localhost/';
+
+mongoose.connect(mongoUri, {
+ useNewUrlParser: true,
+ useUnifiedTopology: true,
+})
+ .catch((err) => {
+ console.error(err);
+ });
+
+
+const db = mongoose.connection;
+
+module.exports = db;
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 | 1x +1x + +1x +1x +1x + + +1x + +1x + + + | const dbCollections = require('./RoomAndReview.js');
+const util = require('./util.js');
+
+const insertRoomsAndReviews = () => {
+ dbCollections.Room.create(util.generate100Rooms());
+ dbCollections.Review.create(util.generate5000Reviews());
+};
+
+insertRoomsAndReviews();
+
+module.export = {
+ insertRoomsAndReviews,
+};
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 | 1x + +1x +1x +1x +5000x + + + + + + +5000x + +1x + + +1x +101x + + + + + + +101x +101x +101x +101x +505x +505x + +101x +101x + + +1x +1x +1x +100x + + + +100x + +1x + + +1x + + + + + | const faker = require('faker');
+
+const generate5000Reviews = () => {
+ const results = [];
+ for (let i = 0; i < 5000; i += 1) {
+ const randomReview = {
+ roomid: i % 100,
+ author: faker.name.firstName(),
+ authorsAvatar: faker.image.imageUrl(),
+ createdAt: faker.date.past(5),
+ text: faker.lorem.sentences(3, 3),
+ };
+ results.push(randomReview);
+ }
+ return results;
+};
+
+const generateAverageRating = () => {
+ const randomAverageRating = {
+ accuracy: faker.random.number({ min: 1, max: 5 }),
+ location: faker.random.number({ min: 1, max: 5 }),
+ cleanliness: faker.random.number({ min: 1, max: 5 }),
+ communication: faker.random.number({ min: 1, max: 5 }),
+ checkIn: faker.random.number({ min: 1, max: 5 }),
+ };
+ let overallRating = 0;
+ let length = 0;
+ const ratingKeys = Object.keys(randomAverageRating);
+ for (let i = 0; i < ratingKeys.length; i += 1) {
+ overallRating += randomAverageRating[ratingKeys[i]];
+ length += 1;
+ }
+ randomAverageRating.overall = overallRating / length;
+ return randomAverageRating;
+};
+
+const generate100Rooms = () => {
+ const results = [];
+ for (let i = 0; i < 100; i += 1) {
+ const randomRoom = {
+ id: i,
+ rating: generateAverageRating(),
+ };
+ results.push(randomRoom);
+ }
+ return results;
+};
+
+module.exports = {
+ generate5000Reviews,
+ generateAverageRating,
+ generate100Rooms,
+};
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| client/components | +
+
+ |
+ 43.48% | +10/23 | +100% | +0/0 | +27.27% | +3/11 | +43.48% | +10/23 | +
| database | +
+
+ |
+ 100% | +33/33 | +100% | +0/0 | +100% | +3/3 | +100% | +30/30 | +