Skip to content

Commit 733345f

Browse files
authored
Merge pull request #2 from josemigallas/dev
adds Travis support and other minor changes
2 parents c125e60 + 67ae4dc commit 733345f

File tree

8 files changed

+57
-19
lines changed

8 files changed

+57
-19
lines changed

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
node_js:
3+
- "4"
4+
env:
5+
- ENV_NODE="development"
6+
before_script:
7+
- npm install
8+
script:
9+
- node dist/src/server.js &
10+
- npm test

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Users RESTful API[ ![Codeship Status for josemigallas/users-api](https://app.codeship.com/projects/017055e0-4b1b-0135-9499-6a83b1829c88/status?branch=master)](https://app.codeship.com/projects/232759)
2-
3-
> :warning: :alien: Due to [this Request issue](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18074) transpilation is failing. It is necessary to fix the bug manually in node_modules/@types/request/typings.d.ts first time after doing an npm install. This is what's causing the failure at deployment on Heroku and testing with Codeship.
1+
# Users RESTful API
2+
[![Build Status](https://travis-ci.org/josemigallas/users-api.svg?branch=master)](https://travis-ci.org/josemigallas/users-api)
43

54
This API allows all CRUDL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.
65

package-lock.json

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"name": "users-api",
33
"version": "0.1.0",
4-
"description": "This API allows all RESTL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.",
4+
"description": "This API allows all CRUDL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.",
55
"scripts": {
66
"start": "node dist/src/server.js",
77
"postinstall": "node_modules/typescript/bin/tsc -p . && cp src/repository/seed.json dist/src/repository/",
88
"test": "node_modules/.bin/jasmine",
9-
"posttest": "rm -r database/test",
10-
"clean": "rm -r node_modules database realm-object-server dist"
9+
"clean": "rm -rf node_modules database realm-object-server dist"
1110
},
1211
"repository": {
1312
"type": "git",
@@ -17,6 +16,7 @@
1716
"license": "ISC",
1817
"dependencies": {
1918
"@types/node": "^8.0.13",
19+
"@types/request": "^2.0.0",
2020
"body-parser": "^1.17.2",
2121
"express": "^4.15.3",
2222
"realm": "^1.10.0",

spec/routes/users.spec.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import RealmHelper from "../../src/repository/realm-helper";
2+
import Sleep from "../../src/utils/sleep";
23

34
import User from "../../src/model/user";
45
import UserDateFilter from "../../src/model/user-date-filter";
@@ -390,13 +391,24 @@ describe("Route users", () => {
390391
const newUser: User = JSON.parse(JSON.stringify(TEST_USER));
391392
newUser.username = "newUser";
392393

393-
it("returns 201 if the user is succesfully created", done => {
394+
it("returns 201 if the user is succesfully created", async done => {
394395
RealmHelper.deleteUser(newUser.username);
395396

397+
await Sleep.millis(200);
398+
399+
const user: User = RealmHelper.getUserByUsername(newUser.username);
400+
expect(user).toBeFalsy();
401+
396402
ApiTestClient
397403
.createUser(newUser)
398-
.then(res => {
404+
.then(async res => {
399405
expect(res.statusCode).toEqual(201);
406+
407+
await Sleep.millis(200);
408+
409+
const createdUser: User = RealmHelper.getUserByUsername(newUser.username);
410+
expect(createdUser).toBeTruthy();
411+
400412
done();
401413
})
402414
.catch(err => {
@@ -432,9 +444,11 @@ describe("Route users", () => {
432444

433445
ApiTestClient
434446
.updateUser(userToUpdate)
435-
.then(res => {
447+
.then(async res => {
436448
expect(res.statusCode).toEqual(200);
437449

450+
await Sleep.millis(200);
451+
438452
const userAfterUpdating: User = RealmHelper.getUserByUsername(userToUpdate.username);
439453
expect(userAfterUpdating.email).toEqual(userToUpdate.email);
440454

@@ -461,9 +475,11 @@ describe("Route users", () => {
461475

462476
ApiTestClient
463477
.updateUser(userToUpdate)
464-
.then(res => {
478+
.then(async res => {
465479
expect(res.statusCode).toEqual(200);
466480

481+
await Sleep.millis(200);
482+
467483
const userAfterUpdating: User = RealmHelper.getUserByUsername(userToUpdate.username);
468484
expect(userAfterUpdating.location.city).toEqual(userToUpdate.location.city);
469485

@@ -504,9 +520,11 @@ describe("Route users", () => {
504520

505521
ApiTestClient
506522
.deleteUser("josemigallas")
507-
.then(res => {
523+
.then(async res => {
508524
expect(res.statusCode).toEqual(200);
509525

526+
await Sleep.millis(200);
527+
510528
const user: User = RealmHelper.getUserByUsername("josemigallas");
511529
expect(user).toBeFalsy();
512530

src/repository/realm-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class RealmHelper {
3434
return this._config;
3535
}
3636

37-
public static init(development = false): void {
37+
public static init(development): void {
3838
if (development) {
3939
this._config.path = "database/test/users";
4040
}

src/utils/sleep.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default class Sleep {
2+
3+
/**
4+
* Waits a certain time of milliseconds.
5+
* @param ms Milliseconds to wait
6+
* @example
7+
* await sleep(1000);
8+
*/
9+
public static millis(ms: number) {
10+
return new Promise(resolve => setTimeout(resolve, ms));
11+
}
12+
13+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"rootDir": ".",
55
"sourceMap": true,
66
"module": "commonjs",
7-
"target": "es5"
7+
"target": "es2015"
88
},
99
"include": [
1010
"./src/**/*",

0 commit comments

Comments
 (0)