Skip to content

Commit

Permalink
Merge pull request #2 from josemigallas/dev
Browse files Browse the repository at this point in the history
adds Travis support and other minor changes
  • Loading branch information
josemigallas authored Jul 21, 2017
2 parents c125e60 + 67ae4dc commit 733345f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 19 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "4"
env:
- ENV_NODE="development"
before_script:
- npm install
script:
- node dist/src/server.js &
- npm test
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# 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)

> :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.
# Users RESTful API
[![Build Status](https://travis-ci.org/josemigallas/users-api.svg?branch=master)](https://travis-ci.org/josemigallas/users-api)

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

Expand Down
10 changes: 4 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "users-api",
"version": "0.1.0",
"description": "This API allows all RESTL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.",
"description": "This API allows all CRUDL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.",
"scripts": {
"start": "node dist/src/server.js",
"postinstall": "node_modules/typescript/bin/tsc -p . && cp src/repository/seed.json dist/src/repository/",
"test": "node_modules/.bin/jasmine",
"posttest": "rm -r database/test",
"clean": "rm -r node_modules database realm-object-server dist"
"clean": "rm -rf node_modules database realm-object-server dist"
},
"repository": {
"type": "git",
Expand All @@ -17,6 +16,7 @@
"license": "ISC",
"dependencies": {
"@types/node": "^8.0.13",
"@types/request": "^2.0.0",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"realm": "^1.10.0",
Expand Down
28 changes: 23 additions & 5 deletions spec/routes/users.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import RealmHelper from "../../src/repository/realm-helper";
import Sleep from "../../src/utils/sleep";

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

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

await Sleep.millis(200);

const user: User = RealmHelper.getUserByUsername(newUser.username);
expect(user).toBeFalsy();

ApiTestClient
.createUser(newUser)
.then(res => {
.then(async res => {
expect(res.statusCode).toEqual(201);

await Sleep.millis(200);

const createdUser: User = RealmHelper.getUserByUsername(newUser.username);
expect(createdUser).toBeTruthy();

done();
})
.catch(err => {
Expand Down Expand Up @@ -432,9 +444,11 @@ describe("Route users", () => {

ApiTestClient
.updateUser(userToUpdate)
.then(res => {
.then(async res => {
expect(res.statusCode).toEqual(200);

await Sleep.millis(200);

const userAfterUpdating: User = RealmHelper.getUserByUsername(userToUpdate.username);
expect(userAfterUpdating.email).toEqual(userToUpdate.email);

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

ApiTestClient
.updateUser(userToUpdate)
.then(res => {
.then(async res => {
expect(res.statusCode).toEqual(200);

await Sleep.millis(200);

const userAfterUpdating: User = RealmHelper.getUserByUsername(userToUpdate.username);
expect(userAfterUpdating.location.city).toEqual(userToUpdate.location.city);

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

ApiTestClient
.deleteUser("josemigallas")
.then(res => {
.then(async res => {
expect(res.statusCode).toEqual(200);

await Sleep.millis(200);

const user: User = RealmHelper.getUserByUsername("josemigallas");
expect(user).toBeFalsy();

Expand Down
2 changes: 1 addition & 1 deletion src/repository/realm-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class RealmHelper {
return this._config;
}

public static init(development = false): void {
public static init(development): void {
if (development) {
this._config.path = "database/test/users";
}
Expand Down
13 changes: 13 additions & 0 deletions src/utils/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default class Sleep {

/**
* Waits a certain time of milliseconds.
* @param ms Milliseconds to wait
* @example
* await sleep(1000);
*/
public static millis(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"rootDir": ".",
"sourceMap": true,
"module": "commonjs",
"target": "es5"
"target": "es2015"
},
"include": [
"./src/**/*",
Expand Down

0 comments on commit 733345f

Please sign in to comment.