├── Section 2 ├── 2.1 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── __tests__ │ │ │ └── company.js │ │ │ ├── models │ │ │ └── Company.js │ │ │ └── package.json │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── __tests__ │ │ └── first.js │ │ └── package.json ├── 2.2 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ └── Company.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ └── company.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── __tests__ │ │ └── company.js │ │ ├── models │ │ └── Company.js │ │ └── package.json ├── 2.3 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ └── Company.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ └── company.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── __tests__ │ │ └── company.js │ │ ├── models │ │ └── Company.js │ │ └── package.json ├── 2.4 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ └── Company.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ └── company.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ └── Company.js │ │ ├── package.json │ │ └── __tests__ │ │ └── company.js └── 2.5 │ └── code │ ├── end │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ └── Company.js │ │ ├── package.json │ │ └── __tests__ │ │ └── company.js │ └── start │ └── taxi-aggregator │ ├── jest.config.js │ ├── models │ └── Company.js │ ├── package.json │ └── __tests__ │ └── company.js ├── Section 3 ├── 3.1 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ └── company.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ └── Company.js │ │ ├── package.json │ │ └── __tests__ │ │ └── company.js ├── 3.3 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ └── company.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ └── company.js ├── 3.4 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ ├── taxi.js │ │ │ └── company.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ └── company.js └── 3.5 │ └── code (1) │ ├── end │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ ├── company.js │ │ └── taxi.js │ └── start │ └── taxi-aggregator │ ├── jest.config.js │ ├── models │ ├── Company.js │ └── Taxi.js │ ├── package.json │ └── __tests__ │ ├── taxi.js │ └── company.js ├── Section 5 ├── 5.1 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ ├── mongoose_features.js │ │ │ ├── company.js │ │ │ └── taxi.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ ├── company.js │ │ └── taxi.js ├── 5.2 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ ├── company.js │ │ │ ├── mongoose_features.js │ │ │ └── taxi.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ ├── mongoose_features.js │ │ ├── company.js │ │ └── taxi.js ├── 5.3 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── package.json │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ └── __tests__ │ │ │ ├── company.js │ │ │ ├── taxi.js │ │ │ └── mongoose_features.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ ├── company.js │ │ ├── mongoose_features.js │ │ └── taxi.js ├── 5.4 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── package.json │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ └── __tests__ │ │ │ ├── company.js │ │ │ └── taxi.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ └── __tests__ │ │ ├── company.js │ │ └── taxi.js └── 5.5 │ └── code │ ├── end │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── models │ │ ├── Taxi.js │ │ └── Company.js │ │ └── __tests__ │ │ ├── company.js │ │ └── taxi.js │ └── start │ └── taxi-aggregator │ ├── jest.config.js │ ├── package.json │ ├── models │ ├── Company.js │ └── Taxi.js │ └── __tests__ │ ├── company.js │ └── taxi.js ├── Section 6 ├── 6.2 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── package.json │ │ │ ├── models │ │ │ ├── Taxi.js │ │ │ └── Company.js │ │ │ └── __tests__ │ │ │ ├── advanced.js │ │ │ ├── company.js │ │ │ └── taxi.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── models │ │ ├── Taxi.js │ │ └── Company.js │ │ └── __tests__ │ │ ├── company.js │ │ └── taxi.js ├── 6.3 │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── package.json │ │ │ ├── models │ │ │ ├── Taxi.js │ │ │ └── Company.js │ │ │ └── __tests__ │ │ │ ├── advanced.js │ │ │ ├── company.js │ │ │ └── taxi.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── models │ │ ├── Taxi.js │ │ └── Company.js │ │ └── __tests__ │ │ ├── advanced.js │ │ ├── company.js │ │ └── taxi.js └── 6.4 │ └── code │ ├── end │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── models │ │ ├── Taxi.js │ │ └── Company.js │ │ └── __tests__ │ │ ├── company.js │ │ └── taxi.js │ └── start │ └── taxi-aggregator │ ├── jest.config.js │ ├── package.json │ ├── models │ ├── Taxi.js │ └── Company.js │ └── __tests__ │ ├── advanced.js │ ├── company.js │ └── taxi.js ├── section 1 ├── 1.7 │ └── code │ │ └── end │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── __tests__ │ │ └── first.js │ │ └── package.json └── 1.7.zip ├── Section 4 ├── 4.2 │ └── code │ │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ ├── operators.js │ │ │ ├── company.js │ │ │ └── taxi.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ ├── company.js │ │ └── taxi.js ├── 4.3 │ └── code (1) │ │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ ├── company.js │ │ │ ├── operators.js │ │ │ └── taxi.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ ├── operators.js │ │ ├── company.js │ │ └── taxi.js ├── 4.4 │ └── code (2) │ │ └── code │ │ ├── end │ │ └── taxi-aggregator │ │ │ ├── jest.config.js │ │ │ ├── models │ │ │ ├── Company.js │ │ │ └── Taxi.js │ │ │ ├── package.json │ │ │ └── __tests__ │ │ │ ├── company.js │ │ │ └── taxi.js │ │ └── start │ │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ ├── company.js │ │ ├── operators.js │ │ └── taxi.js └── 4.5 │ └── code (3) │ └── code │ ├── end │ └── taxi-aggregator │ │ ├── jest.config.js │ │ ├── models │ │ ├── Company.js │ │ └── Taxi.js │ │ ├── package.json │ │ └── __tests__ │ │ ├── company.js │ │ └── taxi.js │ └── start │ └── taxi-aggregator │ ├── jest.config.js │ ├── models │ ├── Company.js │ └── Taxi.js │ ├── package.json │ └── __tests__ │ ├── company.js │ └── taxi.js └── LICENSE /Section 2/2.1/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.2/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.3/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.4/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.5/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 3/3.1/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 3/3.3/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 3/3.4/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.1/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.2/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.3/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.4/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.5/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 6/6.2/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 6/6.3/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 6/6.4/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /section 1/1.7/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.1/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.2/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.3/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.4/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.5/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 3/3.1/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 3/3.3/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 3/3.4/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.1/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.2/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.3/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.4/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 5/5.5/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 6/6.2/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 6/6.3/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 6/6.4/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/end/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/start/taxi-aggregator/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: "node" 3 | }; 4 | -------------------------------------------------------------------------------- /Section 2/2.1/code/start/taxi-aggregator/__tests__/first.js: -------------------------------------------------------------------------------- 1 | test("first test", () => { 2 | expect("name").toBe("name"); 3 | }); 4 | -------------------------------------------------------------------------------- /section 1/1.7.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Hands-on-Developers-Guide-to-MongoDB-4.0/master/section 1/1.7.zip -------------------------------------------------------------------------------- /section 1/1.7/code/end/taxi-aggregator/__tests__/first.js: -------------------------------------------------------------------------------- 1 | test("first test", () => { 2 | expect("name").toBe("name"); 3 | }); 4 | -------------------------------------------------------------------------------- /Section 2/2.1/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | describe("company tests", () => { 5 | //insert tests 6 | test("first test", () => { 7 | expect("name").toBe("name"); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /Section 2/2.1/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 2/2.2/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 2/2.2/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | describe("company tests", () => { 5 | //insert tests 6 | test("first test", () => { 7 | expect("name").toBe("name"); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /Section 2/2.2/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 2/2.3/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 2/2.3/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | describe("company tests", () => { 5 | //insert tests 6 | test("first test", () => { 7 | expect("name").toBe("name"); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /Section 2/2.3/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 2/2.4/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 2/2.4/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 2/2.5/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 2/2.5/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 3/3.1/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 3/3.1/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 3/3.3/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true } 7 | }); 8 | 9 | module.exports = mongoose.model("company", CompanySchema); 10 | -------------------------------------------------------------------------------- /Section 3/3.3/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 3/3.4/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 5/5.1/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 5/5.2/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 3/3.4/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 5/5.1/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 5/5.2/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 5/5.3/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | module.exports = mongoose.model("company", CompanySchema); 11 | -------------------------------------------------------------------------------- /Section 2/2.1/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.2/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.3/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.4/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.5/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.1/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.3/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.4/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.1/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.2/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.3/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.4/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.5/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/6.2/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/6.3/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/6.4/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /section 1/1.7/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.1/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.2/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.3/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.4/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 2/2.5/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.1/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.3/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.4/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.1/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.2/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.3/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.4/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 5/5.5/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/6.2/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/6.3/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/6.4/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/end/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/start/taxi-aggregator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "taxi-aggregator", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --runInBand --watchAll" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.5.5" 13 | }, 14 | "devDependencies": { 15 | "jest": "^24.7.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/3.1/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 3/3.3/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 3/3.4/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 5/5.1/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 3/3.3/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 3/3.4/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 5/5.1/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 5/5.2/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: true }, 12 | model: { type: String, required: true }, 13 | year: { type: Number, required: true }, 14 | owner: OwnerSchema 15 | }); 16 | 17 | module.exports = mongoose.model("taxi", TaxiSchema); 18 | -------------------------------------------------------------------------------- /Section 5/5.3/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | //post save middleware 11 | CompanySchema.post("save", doc => { 12 | //throw error if name equals 'throw error name' 13 | if (doc.name === "throw error name") throw new Error("New Test Error"); 14 | }); 15 | 16 | module.exports = mongoose.model("company", CompanySchema); 17 | -------------------------------------------------------------------------------- /Section 5/5.4/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | //post save middleware 11 | CompanySchema.post("save", doc => { 12 | //throw error if name equals 'throw error name' 13 | if (doc.name === "throw error name") throw new Error("New Test Error"); 14 | }); 15 | 16 | module.exports = mongoose.model("company", CompanySchema); 17 | -------------------------------------------------------------------------------- /Section 5/5.4/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | //post save middleware 11 | CompanySchema.post("save", doc => { 12 | //throw error if name equals 'throw error name' 13 | if (doc.name === "throw error name") throw new Error("New Test Error"); 14 | }); 15 | 16 | //pre save middleware 17 | CompanySchema.pre("save", function(next) { 18 | //sanitize company name before saving 19 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 20 | next(); 21 | }); 22 | 23 | module.exports = mongoose.model("company", CompanySchema); 24 | -------------------------------------------------------------------------------- /Section 5/5.5/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const CompanySchema = new Schema({ 6 | name: { type: String, required: true }, 7 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 8 | }); 9 | 10 | //post save middleware 11 | CompanySchema.post("save", doc => { 12 | //throw error if name equals 'throw error name' 13 | if (doc.name === "throw error name") throw new Error("New Test Error"); 14 | }); 15 | 16 | //pre save middleware 17 | CompanySchema.pre("save", function(next) { 18 | //sanitize company name before saving 19 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 20 | next(); 21 | }); 22 | 23 | module.exports = mongoose.model("company", CompanySchema); 24 | -------------------------------------------------------------------------------- /Section 5/5.2/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 5/5.3/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 5/5.3/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 5/5.4/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 5/5.4/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 5/5.5/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 5/5.5/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 6/6.2/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 6/6.2/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 6/6.3/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const OwnerSchema = new Schema({ 6 | name: { type: String, required: true }, 7 | experience: { type: Number, required: true } 8 | }); 9 | 10 | const TaxiSchema = new Schema({ 11 | brand: { type: String, required: [true, "Brand is required 123"] }, 12 | model: { type: String, required: true }, 13 | year: { 14 | type: Number, 15 | required: true, 16 | validate: { 17 | validator: function(v) { 18 | return /^[0-9]{4}$/.test(v); 19 | }, 20 | message: props => `${props.value} is not a valid year!` 21 | } 22 | }, 23 | owner: OwnerSchema 24 | }); 25 | 26 | module.exports = mongoose.model("taxi", TaxiSchema); 27 | -------------------------------------------------------------------------------- /Section 2/2.2/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | beforeAll(() => { 5 | mongoose.Promise = global.Promise; 6 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 7 | useNewUrlParser: true, 8 | useCreateIndex: true 9 | }); 10 | }); 11 | 12 | beforeEach(() => {}); 13 | 14 | afterEach(async () => { 15 | await Company.deleteMany({}); 16 | }); 17 | 18 | afterAll(done => { 19 | mongoose.disconnect(done); 20 | }); 21 | 22 | describe("company tests", () => { 23 | //insert tests 24 | test("create company", async () => { 25 | let company = new Company(); 26 | company.name = "First Company"; 27 | company = await company.save(); 28 | 29 | const count = await Company.countDocuments(); 30 | expect(count).toBe(1); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /Section 6/6.3/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const PointSchema = new Schema({ 6 | type: { type: String, default: "Point" }, 7 | coordinates: { type: [Number], index: "2dsphere" } //[lng, lat] 8 | }); 9 | 10 | const OwnerSchema = new Schema({ 11 | name: { type: String, required: true }, 12 | experience: { type: Number, required: true } 13 | }); 14 | 15 | const TaxiSchema = new Schema({ 16 | brand: { type: String, required: [true, "Brand is required 123"] }, 17 | model: { type: String, required: true }, 18 | year: { 19 | type: Number, 20 | required: true, 21 | validate: { 22 | validator: function(v) { 23 | return /^[0-9]{4}$/.test(v); 24 | }, 25 | message: props => `${props.value} is not a valid year!` 26 | } 27 | }, 28 | owner: OwnerSchema, 29 | geometry: PointSchema 30 | }); 31 | 32 | module.exports = mongoose.model("taxi", TaxiSchema); 33 | -------------------------------------------------------------------------------- /Section 6/6.4/code/end/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const PointSchema = new Schema({ 6 | type: { type: String, default: "Point" }, 7 | coordinates: { type: [Number], index: "2dsphere" } //[lng, lat] 8 | }); 9 | 10 | const OwnerSchema = new Schema({ 11 | name: { type: String, required: true }, 12 | experience: { type: Number, required: true } 13 | }); 14 | 15 | const TaxiSchema = new Schema({ 16 | brand: { type: String, required: [true, "Brand is required 123"] }, 17 | model: { type: String, required: true }, 18 | year: { 19 | type: Number, 20 | required: true, 21 | validate: { 22 | validator: function(v) { 23 | return /^[0-9]{4}$/.test(v); 24 | }, 25 | message: props => `${props.value} is not a valid year!` 26 | } 27 | }, 28 | owner: OwnerSchema, 29 | geometry: PointSchema 30 | }); 31 | 32 | module.exports = mongoose.model("taxi", TaxiSchema); 33 | -------------------------------------------------------------------------------- /Section 6/6.4/code/start/taxi-aggregator/models/Taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const Schema = mongoose.Schema; 4 | 5 | const PointSchema = new Schema({ 6 | type: { type: String, default: "Point" }, 7 | coordinates: { type: [Number], index: "2dsphere" } //[lng, lat] 8 | }); 9 | 10 | const OwnerSchema = new Schema({ 11 | name: { type: String, required: true }, 12 | experience: { type: Number, required: true } 13 | }); 14 | 15 | const TaxiSchema = new Schema({ 16 | brand: { type: String, required: [true, "Brand is required 123"] }, 17 | model: { type: String, required: true }, 18 | year: { 19 | type: Number, 20 | required: true, 21 | validate: { 22 | validator: function(v) { 23 | return /^[0-9]{4}$/.test(v); 24 | }, 25 | message: props => `${props.value} is not a valid year!` 26 | } 27 | }, 28 | owner: OwnerSchema, 29 | geometry: PointSchema 30 | }); 31 | 32 | module.exports = mongoose.model("taxi", TaxiSchema); 33 | -------------------------------------------------------------------------------- /Section 5/5.1/code/end/taxi-aggregator/__tests__/mongoose_features.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongoose features", () => { 26 | test("default validation", async () => { 27 | try { 28 | let company = new Company(); 29 | await company.save(); 30 | } catch (err) { 31 | expect(err.message).toBe( 32 | "company validation failed: name: Path `name` is required." 33 | ); 34 | } 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /Section 5/5.2/code/start/taxi-aggregator/__tests__/mongoose_features.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongoose features", () => { 26 | test("default validation", async () => { 27 | try { 28 | let company = new Company(); 29 | await company.save(); 30 | } catch (err) { 31 | expect(err.message).toBe( 32 | "company validation failed: name: Path `name` is required." 33 | ); 34 | } 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /Section 5/5.5/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Taxi = require("./Taxi"); 3 | 4 | const Schema = mongoose.Schema; 5 | 6 | const CompanySchema = new Schema({ 7 | name: { type: String, required: true }, 8 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 9 | }); 10 | 11 | //post save middleware 12 | CompanySchema.post("save", doc => { 13 | //throw error if name equals 'throw error name' 14 | if (doc.name === "throw error name") throw new Error("New Test Error"); 15 | }); 16 | 17 | //pre save middleware 18 | CompanySchema.pre("save", function(next) { 19 | //sanitize company name before saving 20 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 21 | next(); 22 | }); 23 | 24 | //pre remove middleware 25 | CompanySchema.pre("remove", async function(next) { 26 | //delete company's taxies before removing company 27 | await Taxi.deleteMany({ _id: { $in: this.taxies } }); 28 | next(); 29 | }); 30 | 31 | module.exports = mongoose.model("company", CompanySchema); 32 | -------------------------------------------------------------------------------- /Section 6/6.2/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Taxi = require("./Taxi"); 3 | 4 | const Schema = mongoose.Schema; 5 | 6 | const CompanySchema = new Schema({ 7 | name: { type: String, required: true }, 8 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 9 | }); 10 | 11 | //post save middleware 12 | CompanySchema.post("save", doc => { 13 | //throw error if name equals 'throw error name' 14 | if (doc.name === "throw error name") throw new Error("New Test Error"); 15 | }); 16 | 17 | //pre save middleware 18 | CompanySchema.pre("save", function(next) { 19 | //sanitize company name before saving 20 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 21 | next(); 22 | }); 23 | 24 | //pre remove middleware 25 | CompanySchema.pre("remove", async function(next) { 26 | //delete company's taxies before removing company 27 | await Taxi.deleteMany({ _id: { $in: this.taxies } }); 28 | next(); 29 | }); 30 | 31 | module.exports = mongoose.model("company", CompanySchema); 32 | -------------------------------------------------------------------------------- /Section 6/6.2/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Taxi = require("./Taxi"); 3 | 4 | const Schema = mongoose.Schema; 5 | 6 | const CompanySchema = new Schema({ 7 | name: { type: String, required: true }, 8 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 9 | }); 10 | 11 | //post save middleware 12 | CompanySchema.post("save", doc => { 13 | //throw error if name equals 'throw error name' 14 | if (doc.name === "throw error name") throw new Error("New Test Error"); 15 | }); 16 | 17 | //pre save middleware 18 | CompanySchema.pre("save", function(next) { 19 | //sanitize company name before saving 20 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 21 | next(); 22 | }); 23 | 24 | //pre remove middleware 25 | CompanySchema.pre("remove", async function(next) { 26 | //delete company's taxies before removing company 27 | await Taxi.deleteMany({ _id: { $in: this.taxies } }); 28 | next(); 29 | }); 30 | 31 | module.exports = mongoose.model("company", CompanySchema); 32 | -------------------------------------------------------------------------------- /Section 6/6.3/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Taxi = require("./Taxi"); 3 | 4 | const Schema = mongoose.Schema; 5 | 6 | const CompanySchema = new Schema({ 7 | name: { type: String, required: true }, 8 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 9 | }); 10 | 11 | //post save middleware 12 | CompanySchema.post("save", doc => { 13 | //throw error if name equals 'throw error name' 14 | if (doc.name === "throw error name") throw new Error("New Test Error"); 15 | }); 16 | 17 | //pre save middleware 18 | CompanySchema.pre("save", function(next) { 19 | //sanitize company name before saving 20 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 21 | next(); 22 | }); 23 | 24 | //pre remove middleware 25 | CompanySchema.pre("remove", async function(next) { 26 | //delete company's taxies before removing company 27 | await Taxi.deleteMany({ _id: { $in: this.taxies } }); 28 | next(); 29 | }); 30 | 31 | module.exports = mongoose.model("company", CompanySchema); 32 | -------------------------------------------------------------------------------- /Section 6/6.3/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Taxi = require("./Taxi"); 3 | 4 | const Schema = mongoose.Schema; 5 | 6 | const CompanySchema = new Schema({ 7 | name: { type: String, required: true }, 8 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 9 | }); 10 | 11 | //post save middleware 12 | CompanySchema.post("save", doc => { 13 | //throw error if name equals 'throw error name' 14 | if (doc.name === "throw error name") throw new Error("New Test Error"); 15 | }); 16 | 17 | //pre save middleware 18 | CompanySchema.pre("save", function(next) { 19 | //sanitize company name before saving 20 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 21 | next(); 22 | }); 23 | 24 | //pre remove middleware 25 | CompanySchema.pre("remove", async function(next) { 26 | //delete company's taxies before removing company 27 | await Taxi.deleteMany({ _id: { $in: this.taxies } }); 28 | next(); 29 | }); 30 | 31 | module.exports = mongoose.model("company", CompanySchema); 32 | -------------------------------------------------------------------------------- /Section 6/6.4/code/end/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Taxi = require("./Taxi"); 3 | 4 | const Schema = mongoose.Schema; 5 | 6 | const CompanySchema = new Schema({ 7 | name: { type: String, required: true }, 8 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 9 | }); 10 | 11 | //post save middleware 12 | CompanySchema.post("save", doc => { 13 | //throw error if name equals 'throw error name' 14 | if (doc.name === "throw error name") throw new Error("New Test Error"); 15 | }); 16 | 17 | //pre save middleware 18 | CompanySchema.pre("save", function(next) { 19 | //sanitize company name before saving 20 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 21 | next(); 22 | }); 23 | 24 | //pre remove middleware 25 | CompanySchema.pre("remove", async function(next) { 26 | //delete company's taxies before removing company 27 | await Taxi.deleteMany({ _id: { $in: this.taxies } }); 28 | next(); 29 | }); 30 | 31 | module.exports = mongoose.model("company", CompanySchema); 32 | -------------------------------------------------------------------------------- /Section 6/6.4/code/start/taxi-aggregator/models/Company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Taxi = require("./Taxi"); 3 | 4 | const Schema = mongoose.Schema; 5 | 6 | const CompanySchema = new Schema({ 7 | name: { type: String, required: true }, 8 | taxies: [{ type: Schema.Types.ObjectId, ref: "taxi" }] 9 | }); 10 | 11 | //post save middleware 12 | CompanySchema.post("save", doc => { 13 | //throw error if name equals 'throw error name' 14 | if (doc.name === "throw error name") throw new Error("New Test Error"); 15 | }); 16 | 17 | //pre save middleware 18 | CompanySchema.pre("save", function(next) { 19 | //sanitize company name before saving 20 | this.name = this.name.replace(/[^a-zA-Z0-9 ]/g, ""); 21 | next(); 22 | }); 23 | 24 | //pre remove middleware 25 | CompanySchema.pre("remove", async function(next) { 26 | //delete company's taxies before removing company 27 | await Taxi.deleteMany({ _id: { $in: this.taxies } }); 28 | next(); 29 | }); 30 | 31 | module.exports = mongoose.model("company", CompanySchema); 32 | -------------------------------------------------------------------------------- /Section 3/3.4/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /Section 2/2.3/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | await Company.deleteMany({}); 22 | }); 23 | 24 | afterAll(done => { 25 | mongoose.disconnect(done); 26 | }); 27 | 28 | describe("company tests", () => { 29 | //insert tests 30 | test("create company", async () => { 31 | const count = await Company.countDocuments(); 32 | expect(count).toBe(1); 33 | }); 34 | 35 | test("read company", async () => { 36 | const readCompany = await Company.findById(company.id); 37 | expect(readCompany.name).toBe(company.name); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /Section 2/2.4/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | await Company.deleteMany({}); 22 | }); 23 | 24 | afterAll(done => { 25 | mongoose.disconnect(done); 26 | }); 27 | 28 | describe("company tests", () => { 29 | //insert tests 30 | test("create company", async () => { 31 | const count = await Company.countDocuments(); 32 | expect(count).toBe(1); 33 | }); 34 | 35 | test("read company", async () => { 36 | const readCompany = await Company.findById(company.id); 37 | expect(readCompany.name).toBe(company.name); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/end/taxi-aggregator/__tests__/operators.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongo operators tests", () => { 26 | test("$gt and $lt", async () => { 27 | // create 5 taxies 28 | for (let i = 1; i <= 5; i++) { 29 | let taxi = new Taxi(); 30 | taxi.brand = "Toyota"; 31 | taxi.model = "Yaris"; 32 | taxi.year = 2015; 33 | taxi.owner = { name: `Driver ${i}`, experience: 5 * i }; 34 | await taxi.save(); 35 | } 36 | 37 | const count = await Taxi.countDocuments(); 38 | expect(count).toBe(5); 39 | 40 | const readTaxies = await Taxi.find({ 41 | "owner.experience": { $gt: 6, $lt: 21 } 42 | }); 43 | 44 | expect(readTaxies.length).toBe(3); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/start/taxi-aggregator/__tests__/operators.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongo operators tests", () => { 26 | test("$gt and $lt", async () => { 27 | // create 5 taxies 28 | for (let i = 1; i <= 5; i++) { 29 | let taxi = new Taxi(); 30 | taxi.brand = "Toyota"; 31 | taxi.model = "Yaris"; 32 | taxi.year = 2015; 33 | taxi.owner = { name: `Driver ${i}`, experience: 5 * i }; 34 | await taxi.save(); 35 | } 36 | 37 | const count = await Taxi.countDocuments(); 38 | expect(count).toBe(5); 39 | 40 | const readTaxies = await Taxi.find({ 41 | "owner.experience": { $gt: 6, $lt: 21 } 42 | }); 43 | 44 | expect(readTaxies.length).toBe(3); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /Section 2/2.4/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | await Company.deleteMany({}); 22 | }); 23 | 24 | afterAll(done => { 25 | mongoose.disconnect(done); 26 | }); 27 | 28 | describe("company tests", () => { 29 | //insert tests 30 | test("create company", async () => { 31 | const count = await Company.countDocuments(); 32 | expect(count).toBe(1); 33 | }); 34 | 35 | test("read company", async () => { 36 | const readCompany = await Company.findById(company.id); 37 | expect(readCompany.name).toBe(company.name); 38 | }); 39 | 40 | test("update company", async () => { 41 | //update existing company 42 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 43 | 44 | //read company 45 | const readCompany = await Company.findById(company.id); 46 | 47 | expect(readCompany.name).toBe("Name modified"); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /Section 2/2.5/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | await Company.deleteMany({}); 22 | }); 23 | 24 | afterAll(done => { 25 | mongoose.disconnect(done); 26 | }); 27 | 28 | describe("company tests", () => { 29 | //insert tests 30 | test("create company", async () => { 31 | const count = await Company.countDocuments(); 32 | expect(count).toBe(1); 33 | }); 34 | 35 | test("read company", async () => { 36 | const readCompany = await Company.findById(company.id); 37 | expect(readCompany.name).toBe(company.name); 38 | }); 39 | 40 | test("update company", async () => { 41 | //update existing company 42 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 43 | 44 | //read company 45 | const readCompany = await Company.findById(company.id); 46 | 47 | expect(readCompany.name).toBe("Name modified"); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /Section 6/6.2/code/end/taxi-aggregator/__tests__/advanced.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("advanced mongodb features", () => { 26 | test("skip and limit", async () => { 27 | for (let i = 0; i < 55; i++) { 28 | let company = new Company(); 29 | company.name = `Company ${i + 1}`; 30 | await company.save(); 31 | } 32 | 33 | const pagination = 10; 34 | let page = 1; 35 | 36 | const firstGroup = await Company.find() 37 | .skip((page - 1) * pagination) 38 | .limit(pagination); 39 | 40 | expect(firstGroup.length).toBe(10); 41 | 42 | page = 6; 43 | const secondGroup = await Company.find() 44 | .skip((page - 1) * pagination) 45 | .limit(pagination); 46 | 47 | expect(secondGroup.length).toBe(5); 48 | expect(secondGroup[0].name).toBe("Company 51"); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /Section 6/6.3/code/end/taxi-aggregator/__tests__/advanced.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("advanced mongodb features", () => { 26 | test("skip and limit", async () => { 27 | for (let i = 0; i < 55; i++) { 28 | let company = new Company(); 29 | company.name = `Company ${i + 1}`; 30 | await company.save(); 31 | } 32 | 33 | const pagination = 10; 34 | let page = 1; 35 | 36 | const firstGroup = await Company.find() 37 | .skip((page - 1) * pagination) 38 | .limit(pagination); 39 | 40 | expect(firstGroup.length).toBe(10); 41 | 42 | page = 6; 43 | const secondGroup = await Company.find() 44 | .skip((page - 1) * pagination) 45 | .limit(pagination); 46 | 47 | expect(secondGroup.length).toBe(5); 48 | expect(secondGroup[0].name).toBe("Company 51"); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /Section 6/6.3/code/start/taxi-aggregator/__tests__/advanced.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("advanced mongodb features", () => { 26 | test("skip and limit", async () => { 27 | for (let i = 0; i < 55; i++) { 28 | let company = new Company(); 29 | company.name = `Company ${i + 1}`; 30 | await company.save(); 31 | } 32 | 33 | const pagination = 10; 34 | let page = 1; 35 | 36 | const firstGroup = await Company.find() 37 | .skip((page - 1) * pagination) 38 | .limit(pagination); 39 | 40 | expect(firstGroup.length).toBe(10); 41 | 42 | page = 6; 43 | const secondGroup = await Company.find() 44 | .skip((page - 1) * pagination) 45 | .limit(pagination); 46 | 47 | expect(secondGroup.length).toBe(5); 48 | expect(secondGroup[0].name).toBe("Company 51"); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /Section 6/6.4/code/start/taxi-aggregator/__tests__/advanced.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("advanced mongodb features", () => { 26 | test("skip and limit", async () => { 27 | for (let i = 0; i < 55; i++) { 28 | let company = new Company(); 29 | company.name = `Company ${i + 1}`; 30 | await company.save(); 31 | } 32 | 33 | const pagination = 10; 34 | let page = 1; 35 | 36 | const firstGroup = await Company.find() 37 | .skip((page - 1) * pagination) 38 | .limit(pagination); 39 | 40 | expect(firstGroup.length).toBe(10); 41 | 42 | page = 6; 43 | const secondGroup = await Company.find() 44 | .skip((page - 1) * pagination) 45 | .limit(pagination); 46 | 47 | expect(secondGroup.length).toBe(5); 48 | expect(secondGroup[0].name).toBe("Company 51"); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /Section 2/2.5/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 3/3.1/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 3/3.3/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 3/3.4/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.1/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.2/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.3/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.4/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.5/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 6/6.2/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 6/6.3/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 6/6.4/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 3/3.1/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 3/3.3/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 3/3.4/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.1/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.2/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.3/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.4/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 5/5.5/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 6/6.2/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 6/6.3/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 6/6.4/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/end/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/start/taxi-aggregator/__tests__/company.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | 4 | let company; 5 | 6 | beforeAll(() => { 7 | mongoose.Promise = global.Promise; 8 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 9 | useNewUrlParser: true, 10 | useCreateIndex: true 11 | }); 12 | }); 13 | 14 | beforeEach(async () => { 15 | company = new Company(); 16 | company.name = "First Company"; 17 | company = await company.save(); 18 | }); 19 | 20 | afterEach(async () => { 21 | //cleanup 22 | await Company.deleteMany({}); 23 | }); 24 | 25 | afterAll(done => { 26 | mongoose.disconnect(done); 27 | }); 28 | 29 | describe("company tests", () => { 30 | //insert tests 31 | test("create company", async () => { 32 | const count = await Company.countDocuments(); 33 | expect(count).toBe(1); 34 | }); 35 | 36 | test("read company", async () => { 37 | const readCompany = await Company.findById(company.id); 38 | expect(readCompany.name).toBe(company.name); 39 | }); 40 | 41 | test("update company", async () => { 42 | //update existing company 43 | await Company.updateOne({ _id: company.id }, { name: "Name modified" }); 44 | 45 | //read company 46 | const readCompany = await Company.findById(company.id); 47 | 48 | expect(readCompany.name).toBe("Name modified"); 49 | }); 50 | 51 | test("delete company", async () => { 52 | const count = await Company.countDocuments(); 53 | expect(count).toBe(1); 54 | 55 | await Company.deleteOne({ _id: company.id }); 56 | 57 | const newCount = await Company.countDocuments(); 58 | expect(newCount).toBe(0); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/end/taxi-aggregator/__tests__/operators.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongo operators tests", () => { 26 | test("$gt and $lt", async () => { 27 | // create 5 taxies 28 | for (let i = 1; i <= 5; i++) { 29 | let taxi = new Taxi(); 30 | taxi.brand = "Toyota"; 31 | taxi.model = "Yaris"; 32 | taxi.year = 2015; 33 | taxi.owner = { name: `Driver ${i}`, experience: 5 * i }; 34 | await taxi.save(); 35 | } 36 | 37 | const count = await Taxi.countDocuments(); 38 | expect(count).toBe(5); 39 | 40 | const readTaxies = await Taxi.find({ 41 | "owner.experience": { $gt: 6, $lt: 21 } 42 | }); 43 | 44 | expect(readTaxies.length).toBe(3); 45 | }); 46 | 47 | test("$in", async () => { 48 | // create 5 taxies 49 | for (let i = 1; i <= 5; i++) { 50 | let taxi = new Taxi(); 51 | taxi.brand = "Toyota"; 52 | taxi.model = "Yaris"; 53 | taxi.year = 2015; 54 | taxi.owner = { name: `Driver ${i}`, experience: 5 * i }; 55 | await taxi.save(); 56 | } 57 | 58 | const taxies = await Taxi.find({ 59 | "owner.experience": { $in: [5, 15, 25, 30] } 60 | }); 61 | 62 | expect(taxies.length).toBe(3); 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/start/taxi-aggregator/__tests__/operators.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongo operators tests", () => { 26 | test("$gt and $lt", async () => { 27 | // create 5 taxies 28 | for (let i = 1; i <= 5; i++) { 29 | let taxi = new Taxi(); 30 | taxi.brand = "Toyota"; 31 | taxi.model = "Yaris"; 32 | taxi.year = 2015; 33 | taxi.owner = { name: `Driver ${i}`, experience: 5 * i }; 34 | await taxi.save(); 35 | } 36 | 37 | const count = await Taxi.countDocuments(); 38 | expect(count).toBe(5); 39 | 40 | const readTaxies = await Taxi.find({ 41 | "owner.experience": { $gt: 6, $lt: 21 } 42 | }); 43 | 44 | expect(readTaxies.length).toBe(3); 45 | }); 46 | 47 | test("$in", async () => { 48 | // create 5 taxies 49 | for (let i = 1; i <= 5; i++) { 50 | let taxi = new Taxi(); 51 | taxi.brand = "Toyota"; 52 | taxi.model = "Yaris"; 53 | taxi.year = 2015; 54 | taxi.owner = { name: `Driver ${i}`, experience: 5 * i }; 55 | await taxi.save(); 56 | } 57 | 58 | const taxies = await Taxi.find({ 59 | "owner.experience": { $in: [5, 15, 25, 30] } 60 | }); 61 | 62 | expect(taxies.length).toBe(3); 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /Section 5/5.2/code/end/taxi-aggregator/__tests__/mongoose_features.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongoose features", () => { 26 | test("default validation", async () => { 27 | try { 28 | let company = new Company(); 29 | await company.save(); 30 | } catch (err) { 31 | expect(err.message).toBe( 32 | "company validation failed: name: Path `name` is required." 33 | ); 34 | } 35 | }); 36 | 37 | test("custom validation simple", async () => { 38 | try { 39 | let taxi = new Taxi(); 40 | taxi.model = "Yaris"; 41 | taxi.year = 2017; 42 | taxi.owner = { name: "Driver 1", experience: 15 }; 43 | taxi = await taxi.save(); 44 | } catch (err) { 45 | expect(err.message).toBe( 46 | "taxi validation failed: brand: Brand is required 123" 47 | ); 48 | } 49 | }); 50 | 51 | test("custom validation advanced", async () => { 52 | try { 53 | let taxi = new Taxi(); 54 | taxi.brand = "Toyota"; 55 | taxi.model = "Yaris"; 56 | taxi.year = 111; 57 | taxi.owner = { name: "Driver 1", experience: 15 }; 58 | taxi = await taxi.save(); 59 | } catch (err) { 60 | expect(err.message).toBe( 61 | "taxi validation failed: year: 111 is not a valid year!" 62 | ); 63 | } 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.3/code/start/taxi-aggregator/__tests__/mongoose_features.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongoose features", () => { 26 | test("default validation", async () => { 27 | try { 28 | let company = new Company(); 29 | await company.save(); 30 | } catch (err) { 31 | expect(err.message).toBe( 32 | "company validation failed: name: Path `name` is required." 33 | ); 34 | } 35 | }); 36 | 37 | test("custom validation simple", async () => { 38 | try { 39 | let taxi = new Taxi(); 40 | taxi.model = "Yaris"; 41 | taxi.year = 2017; 42 | taxi.owner = { name: "Driver 1", experience: 15 }; 43 | taxi = await taxi.save(); 44 | } catch (err) { 45 | expect(err.message).toBe( 46 | "taxi validation failed: brand: Brand is required 123" 47 | ); 48 | } 49 | }); 50 | 51 | test("custom validation advanced", async () => { 52 | try { 53 | let taxi = new Taxi(); 54 | taxi.brand = "Toyota"; 55 | taxi.model = "Yaris"; 56 | taxi.year = 111; 57 | taxi.owner = { name: "Driver 1", experience: 15 }; 58 | taxi = await taxi.save(); 59 | } catch (err) { 60 | expect(err.message).toBe( 61 | "taxi validation failed: year: 111 is not a valid year!" 62 | ); 63 | } 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 3/3.5/code (1)/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.1/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.1/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.2/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.2/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.3/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.3/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.4/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.4/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.5/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.5/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 6/6.2/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 6/6.2/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 6/6.3/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 6/6.3/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 6/6.4/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 6/6.4/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 4/4.2/code/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/end/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 4/4.3/code (1)/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 4/4.4/code (2)/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 4/4.5/code (3)/code/start/taxi-aggregator/__tests__/taxi.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("taxi tests", () => { 26 | test("reading subdocuments", async () => { 27 | let taxi = new Taxi(); 28 | taxi.brand = "Toyota"; 29 | taxi.model = "Yaris"; 30 | taxi.year = 2015; 31 | taxi.owner = { name: "Driver 1", experience: 15 }; 32 | taxi = await taxi.save(); 33 | 34 | const readTaxi = await Taxi.findOne(); 35 | expect(readTaxi.owner.name).toBe("Driver 1"); 36 | }); 37 | 38 | test("populate references", async () => { 39 | let company = new Company(); 40 | company.name = "First Company"; 41 | company = await company.save(); 42 | 43 | let taxi1 = new Taxi(); 44 | taxi1.brand = "Toyota"; 45 | taxi1.model = "Yaris"; 46 | taxi1.year = 2015; 47 | taxi1.owner = { name: "Driver 1", experience: 15 }; 48 | taxi1 = await taxi1.save(); 49 | 50 | let taxi2 = new Taxi(); 51 | taxi2.brand = "Benz"; 52 | taxi2.model = "Class E"; 53 | taxi2.year = 2018; 54 | taxi2.owner = { name: "Driver 2", experience: 7 }; 55 | taxi2 = await taxi2.save(); 56 | 57 | company.taxies = [taxi1.id, taxi2.id]; 58 | company = await company.save(); 59 | 60 | const readCompany = await Company.findById(company.id).populate("taxies"); 61 | 62 | expect(readCompany.taxies[0].model).toBe("Yaris"); 63 | expect(readCompany.taxies[1].model).toBe("Class E"); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /Section 5/5.3/code/end/taxi-aggregator/__tests__/mongoose_features.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const Company = require("../models/Company"); 3 | const Taxi = require("../models/Taxi"); 4 | 5 | beforeAll(() => { 6 | mongoose.Promise = global.Promise; 7 | mongoose.connect("mongodb://localhost/taxi-aggregator", { 8 | useNewUrlParser: true, 9 | useCreateIndex: true 10 | }); 11 | }); 12 | 13 | beforeEach(async () => {}); 14 | 15 | afterEach(async () => { 16 | //cleanup 17 | await Company.deleteMany({}); 18 | await Taxi.deleteMany({}); 19 | }); 20 | 21 | afterAll(done => { 22 | mongoose.disconnect(done); 23 | }); 24 | 25 | describe("mongoose features", () => { 26 | test("default validation", async () => { 27 | try { 28 | let company = new Company(); 29 | await company.save(); 30 | } catch (err) { 31 | expect(err.message).toBe( 32 | "company validation failed: name: Path `name` is required." 33 | ); 34 | } 35 | }); 36 | 37 | test("custom validation simple", async () => { 38 | try { 39 | let taxi = new Taxi(); 40 | taxi.model = "Yaris"; 41 | taxi.year = 2017; 42 | taxi.owner = { name: "Driver 1", experience: 15 }; 43 | taxi = await taxi.save(); 44 | } catch (err) { 45 | expect(err.message).toBe( 46 | "taxi validation failed: brand: Brand is required 123" 47 | ); 48 | } 49 | }); 50 | 51 | test("custom validation advanced", async () => { 52 | try { 53 | let taxi = new Taxi(); 54 | taxi.brand = "Toyota"; 55 | taxi.model = "Yaris"; 56 | taxi.year = 111; 57 | taxi.owner = { name: "Driver 1", experience: 15 }; 58 | taxi = await taxi.save(); 59 | } catch (err) { 60 | expect(err.message).toBe( 61 | "taxi validation failed: year: 111 is not a valid year!" 62 | ); 63 | } 64 | }); 65 | 66 | test("post save middleware", async () => { 67 | try { 68 | let company = new Company(); 69 | company.name = "throw error name"; 70 | await company.save(); 71 | } catch (err) { 72 | expect(err.message).toBe("New Test Error"); 73 | } 74 | }); 75 | }); 76 | --------------------------------------------------------------------------------