Skip to content

Commit

Permalink
Add test and fix forcedSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
Léo Frachet committed Mar 9, 2018
1 parent 9b3f445 commit b1cfbd4
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gtfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Gtfs {
this._shouldThrow = throws;
this._postImportTableFunction = postImportTableFunction;
this._tables = new Map();
this._schema = defaultSchema || forcedSchema;
this._schema = forcedSchema || defaultSchema;
}

/* Input/Output */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A Node.js library for GTFS",
"main": "index.js",
"scripts": {
"test": "mocha tests.js",
"test": "mocha tests/*",
"publish-major": "npm version major && npm publish --access public && git push --tags",
"publish-minor": "npm version minor && npm publish --access public && git push --tags",
"publish-patch": "npm version patch && npm publish --access public && git push --tags"
Expand Down
36 changes: 36 additions & 0 deletions tests/gtfs_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

/* Run the tests with mocha: mocha tests.js */

// eslint-disable-next-line import/no-extraneous-dependencies
const { expect } = require('chai');

const { Gtfs } = require('../index');

describe('Tests on GTFS constructor options', () => {
it('Test on forcedSchema', (done) => {
const forcedSchema = Gtfs.getDefaultSchema();
forcedSchema.deepnessByTableName.modes = 1;
forcedSchema.indexKeysByTableName.modes = { indexKey: 'mode_id' };
forcedSchema.keysByTableName.modes = [
'mode_id',
'mode_name',
'mode_url',
'mode_timezone',
'mode_lang',
'mode_phone',
'mode_fare_url',
'mode_email',
];
forcedSchema.tableNames.push('modes');

const path = `${__dirname}/samples/1/`;
const gtfs = new Gtfs(path, { forcedSchema });

const mode = gtfs.getItemWithIndexInTable('mode_0', 'modes');

expect(mode.mode_name).to.equal('mode 0');

done();
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/samples/1/modes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode_id,mode_name,mode_url,mode_timezone,mode_lang,mode_phone,mode_fare_url,mode_email
mode_0,mode 0,http://google.com,America/New_York,en,(310) 555-0222,http://google.com,contact@google.com
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests.js → tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const { expect } = require('chai');
const fs = require('fs-extra');

const { Gtfs } = require('./index');
const { Gtfs } = require('../index');

describe('Tests on GTFS', () => {
it('Test on meta functions', (done) => {
Expand Down

0 comments on commit b1cfbd4

Please sign in to comment.