Skip to content

Commit 65a01a8

Browse files
committed
[js][data_repository][03_container] Add base
1 parent 2cca108 commit 65a01a8

File tree

9 files changed

+6154
-0
lines changed

9 files changed

+6154
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.tmp/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/preset-env"],
3+
"plugins": ["@babel/plugin-proposal-class-properties"]
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
verbose: true,
4+
cacheDirectory: './.tmp/jestCache',
5+
transform: {'^.+\\.js$': 'babel-jest'},
6+
testMatch:[ "**/tests/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ],
7+
moduleFileExtensions: ['js']
8+
};

examples/js/js-data_repository-03_container/package-lock.json

Lines changed: 6055 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "student_grades",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"jest": {
12+
"moduleFileExtensions": [
13+
"js",
14+
"jsx"
15+
],
16+
"moduleDirectories": [
17+
"node_modules",
18+
"src"
19+
]
20+
},
21+
"devDependencies": {
22+
"@babel/core": "^7.11.6",
23+
"@babel/plugin-proposal-class-properties": "^7.10.4",
24+
"@babel/preset-env": "^7.11.5",
25+
"@jest/globals": "^26.4.2",
26+
"jest": "^26.4.2"
27+
},
28+
"dependencies": {
29+
"sync-mysql": "^3.0.1",
30+
"sync-sql": "^1.0.2"
31+
}
32+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export class MySqlUserRepository {
2+
mysqlHost = "localhost";
3+
mysqlUser = "root";
4+
mysqlPassword = "";
5+
mysqlDatabase = "super_project";
6+
mysqlPort = 3306;
7+
8+
constructor() {
9+
const Mysql = require('sync-mysql');
10+
this.connection = new Mysql({
11+
host: this.mysqlHost,
12+
user: this.mysqlUser,
13+
password: this.mysqlPassword,
14+
database: this.mysqlDatabase,
15+
port: this.mysqlPort
16+
});
17+
}
18+
19+
searchAll() {
20+
return this.connection.query('SELECT * FROM users');
21+
}
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class UsersSearcher {
2+
constructor(repository) {
3+
this.repository = repository;
4+
}
5+
6+
searchAll() {
7+
return this.repository.searchAll();
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class FakeUserRepository {
2+
constructor(users) {
3+
this.users = users;
4+
}
5+
6+
searchAll() {
7+
return this.users;
8+
}
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {FakeUserRepository} from "./FakeUserRepository";
2+
import {UsersSearcher} from "../src/UsersSearcher";
3+
4+
describe('UsersSearcher should', () => {
5+
it('search all existing users', () => {
6+
const existingUsers = [{"name": "javi"}, {"name": "rafa"}];
7+
8+
const repository = new FakeUserRepository(existingUsers);
9+
const searcher = new UsersSearcher(repository);
10+
11+
expect(searcher.searchAll()).toBe(existingUsers);
12+
});
13+
});

0 commit comments

Comments
 (0)