<commit_before>const assert = require('chai').assert;
const expect = require('chai').expect;
const request = require('request');

const mvgHeader = {
    "X-MVG-Authorization-Key": "5af1beca494712ed38d313714d4caff6"
}

/*
* I make assumptions about the MVG api. If it changes, the library
* may break.
* 
* To find out if that happens, I include some tests that chech the 
* MVG api directly.
*/

describe('The MVG Endpoint for', () => {
    describe('stations', () => {
        it('should return a response with the expected JSON structure.', (done) => {
            // GIVEN
            const stationEndpoint = 'https://www.mvg.de/api/fahrinfo/location/query?q=Hauptbahnhof';

            // WHEN
            request.get(
                {
                    uri: stationEndpoint,
                    encoding: null,
                    headers: mvgHeader
                }, (error, response, body) =>
                {
                    // THEN
                    expect(JSON.parse.bind(body)).to.not.throw('Couldn\t parse JSON.');
                    const bodyJson = JSON.parse(body);

                    assert.isArray(bodyJson.locations, "Locations array is not present .");
                    assert.isAbove(bodyJson.locations.length, 0, "No location found in the returned JSON.")
                    const station = bodyJson.locations[0];

                    assert.containsAllKeys(station, ['id'], "JSON for station did not contain station id.")                    
                    
                    done();
                }
            )
        })
    })

    describe('departures', () => {
        it('should return a response with the expected JSON structure.', (done) => {
            // GIVEN
            const departureIdEndpoint = 'https://www.mvg.de/api/fahrinfo/departure/6?footway=0';

            // WHEN
            request.get(
                {
                    uri: departureIdEndpoint,
                    encoding: null,
                    headers: mvgHeader
                }, (error, response, body) =>
                {
                    // THEN
                    expect(JSON.parse.bind(body)).to.not.throw('Couldn\t parse JSON.');
                    const bodyJson = JSON.parse(body);

                    assert.isArray(bodyJson.departures, "Departures array is not present .");
                    assert.isAbove(bodyJson.departures.length, 0, "No departures found in the returned JSON.")
                    const departure = bodyJson.departures[0];

                    const expectedKeys = ['label', 'destination', 'departureTime', 'product'];
                    assert.containsAllKeys(departure, expectedKeys, "JSON for departure did not contain station id.");

                    const product = departure.product;
                    assert.oneOf(product, ['UBAHN', 'SBAHN', 'BUS', 'TRAM'], 'The type of transportation was of unknown kind.')

                    const label = departure.label;

                    expect(label).to.satisfy((label) => {
                        switch(product){
                            case 'UBAHN': return label.startsWith('U');
                            case 'SBAHN': return label.startsWith('S');
                            default: return !isNaN(parseInt(label));
                        }
                    })

                    done();
                }
            )
        })
    })
})<commit_msg>Add 'REGIONAL_BUS' to list of expected types of transportation in test<commit_after>const assert = require('chai').assert;
const expect = require('chai').expect;
const request = require('request');

const mvgHeader = {
    "X-MVG-Authorization-Key": "5af1beca494712ed38d313714d4caff6"
}

/*
* I make assumptions about the MVG api. If it changes, the library
* may break.
* 
* To find out if that happens, I include some tests that chech the 
* MVG api directly.
*/

describe('The MVG Endpoint for', () => {
    describe('stations', () => {
        it('should return a response with the expected JSON structure.', (done) => {
            // GIVEN
            const stationEndpoint = 'https://www.mvg.de/api/fahrinfo/location/query?q=Hauptbahnhof';

            // WHEN
            request.get(
                {
                    uri: stationEndpoint,
                    encoding: null,
                    headers: mvgHeader
                }, (error, response, body) =>
                {
                    // THEN
                    expect(JSON.parse.bind(body)).to.not.throw('Couldn\t parse JSON.');
                    const bodyJson = JSON.parse(body);

                    assert.isArray(bodyJson.locations, "Locations array is not present .");
                    assert.isAbove(bodyJson.locations.length, 0, "No location found in the returned JSON.")
                    const station = bodyJson.locations[0];

                    assert.containsAllKeys(station, ['id'], "JSON for station did not contain station id.")                    
                    
                    done();
                }
            )
        })
    })

    describe('departures', () => {
        it('should return a response with the expected JSON structure.', (done) => {
            // GIVEN
            const departureIdEndpoint = 'https://www.mvg.de/api/fahrinfo/departure/6?footway=0';

            // WHEN
            request.get(
                {
                    uri: departureIdEndpoint,
                    encoding: null,
                    headers: mvgHeader
                }, (error, response, body) =>
                {
                    // THEN
                    expect(JSON.parse.bind(body)).to.not.throw('Couldn\t parse JSON.');
                    const bodyJson = JSON.parse(body);

                    assert.isArray(bodyJson.departures, "Departures array is not present .");
                    assert.isAbove(bodyJson.departures.length, 0, "No departures found in the returned JSON.")
                    const departure = bodyJson.departures[0];

                    const expectedKeys = ['label', 'destination', 'departureTime', 'product'];
                    assert.containsAllKeys(departure, expectedKeys, "JSON for departure did not contain station id.");

                    const product = departure.product;
                    assert.oneOf(product, ['UBAHN', 'SBAHN', 'BUS', 'REGIONAL_BUS', 'TRAM'], 'The type of transportation was of unknown kind.')

                    const label = departure.label;

                    expect(label).to.satisfy((label) => {
                        switch(product){
                            case 'UBAHN': return label.startsWith('U');
                            case 'SBAHN': return label.startsWith('S');
                            default: return !isNaN(parseInt(label));
                        }
                    })

                    done();
                }
            )
        })
    })
})
{'fraction_non_alphanumeric': 0.1122700275242648, 'fraction_numerical': 0.006953498478922208, 'mean_word_length': 1.443029016277424, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5075164', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1687, 'n_words': 429}