Skip to content

Commit 9277a2d

Browse files
authored
Merge changes to master (#68)
* Fizx logo on README * Sydney Coding Dojos session 27 September 2018 - BCG
1 parent ec9ee83 commit 9277a2d

File tree

9 files changed

+5989
-0
lines changed

9 files changed

+5989
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
This is a Kata which aims at developing a Node API for creating a personal Movie Database using Test Driven Development[TDD] approach
2+
3+
## Requirements
4+
- good understanding of JavaScript
5+
- basic knowledge of server/client request/response
6+
- basic understanding of HTTP
7+
- basic understanding of GIT
8+
9+
## Development using
10+
- Node.js
11+
- TDD approach
12+
- [Postman](https://www.getpostman.com/) - API development environment
13+
- [Robo 3T](https://robomongo.org/) - a free lightweight GUI for MongoDB enthusiasts
14+
15+
16+
## User Story 1
17+
1. As a User I want to insert movie information to create my own movie database.
18+
19+
### Acceptance Criteria
20+
- The movie to be inserted must have title and description
21+
- User cannot enter the same movie name again i.e duplicates must be tracked based on the title of the movie
22+
- The user must send the data to the API in JSON format
23+
24+
## User Story 2
25+
Coming soon...
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const isDuplicated = (movieCollection, movieName) =>
2+
movieCollection.some(movie => movie.title === movieName);
3+
4+
const createMovie = database => (title, description) => {
5+
if (title === "" && description === "") {
6+
return "Movie title and description was required";
7+
} else if (title === "") {
8+
return "Movie title was required";
9+
} else if (description === "") {
10+
return "Movie description was required";
11+
}
12+
13+
const allMovies = database.getAll();
14+
15+
if (isDuplicated(allMovies, title)) {
16+
return "Movie name is duplicate.";
17+
}
18+
19+
return JSON.stringify(database.saveData());
20+
};
21+
22+
module.exports = createMovie;
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
const createMovie = require("./create-movie");
2+
3+
describe("Create movie", () => {
4+
it("Requires movie with a title", () => {
5+
const fakeDatabase = {
6+
getAll: () => {},
7+
saveData: () => {}
8+
};
9+
const title = "";
10+
const description = "some description here";
11+
const mockCreateMovie = jest.spyOn(fakeDatabase, "getAll");
12+
expect(createMovie(fakeDatabase)(title, description)).toBe(
13+
"Movie title was required"
14+
);
15+
expect(mockCreateMovie).not.toHaveBeenCalled();
16+
});
17+
18+
it("Requires movie with a description", () => {
19+
const fakeDatabase = {
20+
getAll: () => {},
21+
saveData: () => {}
22+
};
23+
const title = "Star Wars";
24+
const description = "";
25+
const mockCreateMovie = jest.spyOn(fakeDatabase, "getAll");
26+
expect(createMovie(fakeDatabase)(title, description)).toBe(
27+
"Movie description was required"
28+
);
29+
expect(mockCreateMovie).not.toHaveBeenCalled();
30+
});
31+
32+
it("Requires movie with a title and a description", () => {
33+
const title = "";
34+
const description = "";
35+
expect(createMovie()(title, description)).toBe(
36+
"Movie title and description was required"
37+
);
38+
});
39+
40+
it("Should not have duplicate movie name", () => {
41+
const fakeDatabase = {
42+
getAll: () => {
43+
return [
44+
{ title: "DespicableMe", description: "Comedy" },
45+
{ title: "DespicableMe2", description: "Comedy" },
46+
{ title: "DespicableMe3", description: "Comedy" }
47+
];
48+
}
49+
};
50+
expect(createMovie(fakeDatabase)("DespicableMe", "Comedy")).toBe(
51+
"Movie name is duplicate."
52+
);
53+
});
54+
55+
it("Should save the data in JSON format", () => {
56+
const fakeDatabase = {
57+
getAll: () => {
58+
return [
59+
{
60+
id: 1,
61+
title: "DespicableMe",
62+
description: "Comedy"
63+
}
64+
];
65+
},
66+
saveData: () => {
67+
return {
68+
id: 2,
69+
title: "DespicableMe2",
70+
description: "Comedy"
71+
};
72+
}
73+
};
74+
75+
const expectedData = {
76+
id: 2,
77+
title: "DespicableMe2",
78+
description: "Comedy"
79+
};
80+
81+
expect(createMovie(fakeDatabase)("DespicableMe2", "Comedy")).toBe(
82+
JSON.stringify(expectedData)
83+
);
84+
});
85+
86+
it("Should call the getAll method once", () => {
87+
const fakeDatabase = {
88+
getAll: () => {
89+
return [
90+
{
91+
id: 1,
92+
title: "DespicableMe",
93+
description: "Comedy"
94+
}
95+
];
96+
},
97+
saveData: () => {
98+
return {
99+
id: 2,
100+
title: "DespicableMe2",
101+
description: "Comedy"
102+
};
103+
}
104+
};
105+
106+
const mockCreateMovie = jest.spyOn(fakeDatabase, "getAll");
107+
const result = createMovie(fakeDatabase)("DespicableMe2", "Comedy");
108+
109+
expect(mockCreateMovie).toHaveBeenCalled();
110+
});
111+
});

0 commit comments

Comments
 (0)