Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

second.js #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

second.js #3

wants to merge 1 commit into from

Conversation

etcohen
Copy link

@etcohen etcohen commented Jun 7, 2018

'use strict';

const assert = require('assert');

const request = require('request-promise');

const sinon = require('sinon');

const TableService = require('../lib/tableService');

const exampleResponse = require('./tableService.json');

describe('The TableService component', function () {

it ('Initialisation', function() {

    var service = new TableService('http://www.example.com');

    assert(service.url, 'http://www.example.com');

});



it('Get Specific Team Positions', function () {

    var service = new TableService('http://www.example.com');



    var requestStub = this.sandbox.stub(request, 'call');

    requestStub.returns(Promise.resolve(exampleResponse));



    var answers = {

        'Bath Rugby': {

            'position': 2,

            'teamName': 'Bath Rugby',

            'played': 2,

            'won': 2,

            'drawn': 0,

            'lost': 0,

            'pointsFor': 76,

            'pointsAgainst': 19,

            'bonusPoints': 1,

            'points': 9

        },

        'Gloucester Rugby': {

            'position': 9,

            'teamName': 'Gloucester Rugby',

            'played': 2,

            'won': 0,

            'drawn': 1,

            'lost': 1,

            'pointsFor': 54,

            'pointsAgainst': 61,

            'bonusPoints': 2,

            'points': 4

        }

    };



    /** @type {TablePosition} */

    return service.getPositions(['bath rugby', 'Gloucester Rugby'])

        .then(positions => {

            for (let position of positions) {

                if (position.teamName in answers) {

                    let team = answers[position.teamName];

                    assert.deepEqual(position.position, team.position);

                    assert.deepEqual(position.teamName, team.teamName);

                    assert.deepEqual(position.played, team.played);

                    assert.deepEqual(position.won, team.won);

                    assert.deepEqual(position.drawn, team.drawn);

                    assert.deepEqual(position.lost, team.lost);

                    assert.deepEqual(position.pointsFor, team.pointsFor);

                    assert.deepEqual(position.pointsAgainst, team.pointsAgainst);

                    assert.deepEqual(position.bonusPoints, team.bonusPoints);

                    assert.deepEqual(position.points, team.points);

                } else {

                    throw Error(position.teamName + ' should not have been returned');

                }

            }



            if (positions.length !== Object.keys(answers).length) {

                throw Error('Incorrect number of team positions returned');

            }

        });

});

});

@bobbyshaw
Copy link
Owner

Hi, thanks for the contribution but I don't see what these changes achieve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants