Skip to content

Commit

Permalink
#39 Initial Commit + Rename Training model to TrainingEntity + functi…
Browse files Browse the repository at this point in the history
…on GetTrainingById in ApiRest and spec
  • Loading branch information
borjamaza committed Dec 8, 2016
1 parent 8d34926 commit 289f574
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/model/spec/training.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect } from 'chai';
import {} from 'mocha'
import {} from 'core-js'
import {Training} from '../training';
import {TrainingEntity} from '../training';
import {Student} from '../student';
import {Trainer} from '../trainer';

describe('Training', () => {
let training : Training = null;
let training : TrainingEntity = null;

beforeEach(() => {
training = new Training();
training = new TrainingEntity();
});

it('Is instantiated and exists', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/model/training.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Student} from "./student";
import {Trainer} from "./trainer";

export class Training {
export class TrainingEntity {
id : number;
name : string;
isActive : boolean;
Expand Down
25 changes: 22 additions & 3 deletions src/rest-api/spec/training.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from 'chai';
import {} from 'mocha'
import {} from 'core-js'
import { Training } from '../../model/training';
import { TrainingEntity } from '../../model/training';
import { Student } from '../../model/student';
import { Trainer } from '../../model/trainer';
import {TrainingSummary} from '../../model/trainingSummary';
import { trainingApi } from '../training'

let trainingList : Training[];
let trainingList : TrainingEntity[];

beforeEach(() => {
trainingList = [
Expand Down Expand Up @@ -80,6 +80,25 @@ describe('TrainingApi', () => {
expect(summaryList).to.eql(expectedSummaryList);
done();
});
}).bind(this))
}).bind(this));
});
describe('getTrainingById', () => {
it('Get the expected training', sinon.test((done) => {
// Arrange
const id: number = 32;
let expectedTraining : TrainingEntity;

// Act
expectedTraining = trainingList.find(training => training.id === id);


const fetchTraining = trainingApi.getTrainingById(id);

fetchTraining.then((training) => {
// Assert
expect(training).to.eql(expectedTraining);
done();
});
}).bind(this));
});
});
16 changes: 10 additions & 6 deletions src/rest-api/training.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Training } from '../model/training'
import { TrainingSummary } from '../model/trainingSummary'
import { trainingMockData } from './trainingMockData'

import { TrainingSummary } from '../model/trainingSummary';
import { trainingMockData } from './trainingMockData';
import { TrainingEntity } from '../model/training';
class TrainingApi {
trainingList : Training[];
trainingList : TrainingEntity[];

constructor() {
this.trainingList = trainingMockData;
}

setMockDataSeed(trainingList : Training[]) {
setMockDataSeed(trainingList : TrainingEntity[]) {
this.trainingList = trainingList;
}

Expand All @@ -24,6 +23,11 @@ class TrainingApi {

return Promise.resolve(trainingSummaryList);
}

getTrainingById(id: number): Promise<TrainingEntity> {
const training = this.trainingList.find(tr => tr.id === id);
return Promise.resolve(training);
}
}

export const trainingApi = new TrainingApi();
4 changes: 2 additions & 2 deletions src/rest-api/trainingMockData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Training } from '../model/training'
import { TrainingEntity } from '../model/training'
import { Student } from '../model/student'
import { Trainer } from '../model/trainer'

export const trainingMockData : Training[] =
export const trainingMockData : TrainingEntity[] =
[
{
id: 32,
Expand Down

0 comments on commit 289f574

Please sign in to comment.