Skip to content

Commit

Permalink
upgrade incept and update test (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianadevargas authored Jan 18, 2018
1 parent 5e278a2 commit 27da705
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 225 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rm -rf dist docs && mkdir docs",
"test": "NODE_ENV=test nyc --reporter=lcov mocha",
"itest": "NODE_ENV=test nyc --reporter=lcov --report-dir=icoverage mocha itest",
Expand Down Expand Up @@ -41,7 +42,7 @@
"config": "1.25.1",
"csvjson": "^4.3.3",
"csvtojson": "^1.1.7",
"inceptum": "^0.5.17",
"inceptum": "^0.5.47",
"lodash": "^4.17.4",
"moment": "^2.18.1",
"moment-timezone": "^0.5.14",
Expand All @@ -65,11 +66,11 @@
"nock": "^9.0.14",
"nyc": "^10.3.2",
"sinon": "^3.2.0",
"ts-node": "3.0.4",
"tslint": "^5.4.3",
"tslint-config-shopify": "^2.0.0",
"typedoc": "^0.7.1",
"typedoc-clarity-theme": "^1.1.0"
"ts-node": "4.0.1",
"tslint": "^5.8.0",
"tslint-config-shopify": "2.0.0",
"typedoc-clarity-theme": "^1.1.0",
"typescript": "2.6.1"
},
"nyc": {
"include": [
Expand Down
5 changes: 3 additions & 2 deletions src/util/GoogleAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as promise from 'bluebird';
import * as google from 'googleapis';
import { LogManager } from 'inceptum';
// Helper function
import { GoogleAnalyticsReporting } from '../sources/GoogleAnalyticsReporting';
import RequestGenerator from './RequestGenerator';

const log = LogManager.getLogger();
Expand Down Expand Up @@ -65,8 +66,8 @@ export class GoogleAnalytics {
*/
public async fetch(params): Promise<any> {
try {
const analytics = await this.authorize();
const report = promise.promisify(analytics.reports.batchGet);
const analytics: google.analyticsreporting = await this.authorize();
const report: google.analyticsreporting.reports.batchGet = promise.promisify(analytics.reports.batchGet);
const requestGen = new RequestGenerator();
const response = await report({
resource: requestGen
Expand Down
6 changes: 4 additions & 2 deletions test/ConfigPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { must } from 'must';
import { suite, test, slow, timeout, skip } from 'mocha-typescript';
import { InceptumApp, BaseSingletonDefinition } from 'inceptum';
import BaseApp from 'inceptum/dist/app/BaseApp';
import { BaseSingletonDefinition } from 'inceptum';
import { ConfigPlugin } from '../src/ConfigPlugin';

class EmptyClass {
Expand All @@ -10,7 +11,7 @@ class EmptyClass {
}
}

const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const etlName = 'test_1';

Expand Down Expand Up @@ -40,6 +41,7 @@ suite('Config Plugin', () => {
config.getEtlDestination().must.be.eql(obj);
config.getEtlTransformer().must.be.eql(obj);
config.getEtlSavepointManager().must.be.eql(obj);
await app.stop();
});
});
});
6 changes: 4 additions & 2 deletions test/RunnerPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { must } from 'must';
import { suite, test, slow, timeout, skip } from 'mocha-typescript';
import { InceptumApp, BaseSingletonDefinition } from 'inceptum';
import BaseApp from 'inceptum/dist/app/BaseApp';
import { BaseSingletonDefinition } from 'inceptum';
import { SavepointPlugin } from '../src/savepoints/SavepointPlugin';
import { DestinationPlugin } from '../src/destinations/DestinationPlugin';
import { TransformerPlugin } from '../src/transformers/TransformerPlugin';
Expand All @@ -15,7 +16,7 @@ class EmptyClass {
}
}

const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const etlName = 'test_1';

Expand All @@ -34,6 +35,7 @@ suite('Runner plugin', () => {
const runner = await context.getObjectByName('EtlRunner');
const theType = runner.constructor.name;
theType.must.be.equal('EtlRunner');
await app.stop();
});
});
});
15 changes: 10 additions & 5 deletions test/destinations/DestinationPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { must } from 'must';
import { suite, test, slow, timeout, skip } from 'mocha-typescript';
import { InceptumApp, Context, BaseSingletonDefinition } from 'inceptum';
import BaseApp from 'inceptum/dist/app/BaseApp';
import { Context, BaseSingletonDefinition } from 'inceptum';
import { EtlDestination } from '../../src/EtlDestination';
import { EtlBatch, EtlState } from '../../src/EtlBatch';
import { DestinationPlugin } from '../../src/destinations/DestinationPlugin';
Expand Down Expand Up @@ -36,37 +37,40 @@ class ExtendedDestinationPlugin extends DestinationPlugin {
suite('DestinationPlugin', () => {
suite('Destination plugin test', () => {
test('Basic ', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const pluginObj = new DestinationPlugin('test_1');
app.use(pluginObj);
await app.start();
const destination = await context.getObjectByName('EtlDestination');
const theType = destination.constructor.name;
theType.must.be.equal('CsvFile');
await app.stop();
});
test('Basic destination load with extended config ', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const pluginObj = new ExtendedDestinationPlugin('test_1');
app.use(pluginObj);
await app.start();
const destination = await context.getObjectByName('EtlDestination');
const theType = destination.constructor.name;
theType.must.be.equal('CsvFile');
await app.stop();
});
test('Extended destination load', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const pluginObj = new ExtendedDestinationPlugin('test_7');
app.use(pluginObj);
await app.start();
const destination = await context.getObjectByName('EtlDestination');
const theType = destination.constructor.name;
theType.must.be.equal('ExtendedDestination');
await app.stop();
});
test('Basic not extended destination error', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
try {
const pluginObj = new DestinationPlugin('test_7');
Expand All @@ -75,6 +79,7 @@ suite('DestinationPlugin', () => {
} catch (err) {
err.message.must.be.equal('Unknown destination type: extendeddestination');
}
await app.stop();
});
});
});
35 changes: 24 additions & 11 deletions test/destinations/MySqlInsert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import * as moment from 'moment';
import * as utilConfig from 'config';
import { suite, test, slow, timeout, skip } from 'mocha-typescript';
// Internal dependencies
import { DBClient, DBTransaction, InceptumApp, BaseSingletonDefinition } from 'inceptum';
import BaseApp from 'inceptum/dist/app/BaseApp';
import { DBClient, DBTransaction, BaseSingletonDefinition } from 'inceptum';
import { Transaction } from 'inceptum/dist/transaction/TransactionManager';
import { EtlBatch, EtlState } from '../../src/EtlBatch';
import { SavepointPlugin } from '../../src/savepoints/SavepointPlugin';
import { DestinationPlugin } from '../../src/destinations/DestinationPlugin';
import { MySqlInsert, MysqlQueryHelper, MysqlQueryBuilderHelper } from '../../src/destinations/MySqlInsert';

Expand Down Expand Up @@ -272,37 +274,48 @@ suite('MySqlInsert', () => {
});
});
suite('Test using the plugin:', () => {
const app = new InceptumApp();
const dbSingletonDefinition = new BaseSingletonDefinition(TestDBClient, 'EtlSavePoint');
const app = new BaseApp();
const context = app.getContext();
context.registerSingletons(dbSingletonDefinition);
const pluginObj = new DestinationPlugin('test_16');
app.use(pluginObj);
let dest: any;
before('start', async () => {
app.use(pluginObj);
await app.start();
dest = await context.getObjectByName('EtlDestination');
});

test('The type of object:', async () => {
await app.start();
const dest = await context.getObjectByName('EtlDestination');
dest.must.be.instanceof(MySqlInsert);
});

test('Initial config values', async () => {
const dest = await context.getObjectByName('EtlDestination');
dest.getMySqlClient().must.be.instanceOf(DBClient);
dest.getTableName().must.be.equal('test_table');
dest.getBulkDeleteMatchFields().must.be.an.array();
dest.getBulkDeleteMatchFields().must.be.eql(testConfig.bulkDeleteMatchFields);
});

after('stop', async () => {
await app.stop();
});
});
suite('Test using the plugin no delete fields:', () => {
const app = new InceptumApp();
const context = app.getContext();
const pluginObj = new DestinationPlugin('test_17');
app.use(pluginObj);

test('Initial config values', async () => {
const dbSingletonDefinition = new BaseSingletonDefinition(TestDBClient, 'EtlSavePoint');
const app = new BaseApp();
const context = app.getContext();
context.registerSingletons(dbSingletonDefinition);
const pluginObj = new DestinationPlugin('test_17');
app.use(pluginObj);
await app.start();
const dest = await context.getObjectByName('EtlDestination');
dest.getMySqlClient().must.be.instanceOf(DBClient);
dest.getTableName().must.be.equal('test_table');
dest.getBulkDeleteMatchFields().must.be.an.boolean();
dest.getBulkDeleteMatchFields().must.be.equal(false);
await app.stop();
});
});

Expand Down
15 changes: 10 additions & 5 deletions test/savepoints/SavepointPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { must } from 'must';
import { suite, test, slow, timeout, skip } from 'mocha-typescript';
import { Context, InceptumApp, BaseSingletonDefinition } from 'inceptum';
import BaseApp from 'inceptum/dist/app/BaseApp';
import { Context, BaseSingletonDefinition } from 'inceptum';
import { EtlSavepointManager } from '../../src/EtlSavepointManager';
import { EtlBatch, EtlState } from '../../src/EtlBatch';
import { SavepointPlugin } from '../../src/savepoints/SavepointPlugin';
Expand Down Expand Up @@ -35,34 +36,37 @@ class ExtendedSavepointPlugin extends SavepointPlugin {

suite('Savepoint Plugin test', () => {
test('Basic ', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const savepoints = new SavepointPlugin('test_2');
app.use(savepoints);
await app.start();
const savepoint = await context.getObjectByName('EtlSavepointManager');
savepoint.must.be.instanceof(StaticSavepointManager);
await app.stop();
});
test('Basic savepoint load with extended config ', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const savepoints = new ExtendedSavepointPlugin('test_2');
app.use(savepoints);
await app.start();
const savepoint = await context.getObjectByName('EtlSavepointManager');
savepoint.must.be.instanceof(StaticSavepointManager);
await app.stop();
});
test('Extended savepoint load', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const savepoints = new ExtendedSavepointPlugin('test_7');
app.use(savepoints);
await app.start();
const savepoint = await context.getObjectByName('EtlSavepointManager');
savepoint.must.be.instanceof(ExtendedSavepoint);
await app.stop();
});
test('Basic not extended savepoint error', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
try {
const savepoints = new SavepointPlugin('test_7');
Expand All @@ -72,5 +76,6 @@ suite('Savepoint Plugin test', () => {
} catch (err) {
err.message.must.be.equal('Unknown savepoint type: extendedsavepoint');
}
await app.stop();
});
});
17 changes: 12 additions & 5 deletions test/sources/AdwordsReportLargeFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { must } from 'must';
import * as utilConfig from 'config';
import { suite, test, slow, timeout, skip } from 'mocha-typescript';
import * as moment from 'moment';
import { InceptumApp } from 'inceptum';
import BaseApp from 'inceptum/dist/app/BaseApp';
import { EtlBatch, EtlState } from '../../src/EtlBatch';
import { StaticSavepointManager } from '../../src/savepoints/StaticSavepointManager';
import { AdwordsReportLargeFile } from '../../src/sources/AdwordsReportLargeFile';
Expand Down Expand Up @@ -265,12 +265,15 @@ suite('AdwordsReportLargeFile', () => {
});

suite('Test using the plugin to ensure the parameters are passed:', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const pluginObj = new SourcePlugin('test_14');
app.use(pluginObj);
await app.start();
const source = await context.getObjectByName('EtlSource');
let source: any;
before('start', async () => {
app.use(pluginObj);
await app.start();
source = await context.getObjectByName('EtlSource');
});

test('the type of object:', async () => {
source.must.be.instanceof(AdwordsReportLargeFile);
Expand All @@ -292,5 +295,9 @@ suite('AdwordsReportLargeFile', () => {
version: 'v201705',
});
});

after('stop', async () => {
await app.stop();
});
});
});
17 changes: 12 additions & 5 deletions test/sources/AdwordsReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { must } from 'must';
import * as utilConfig from 'config';
import { suite, test, slow, timeout, skip } from 'mocha-typescript';
import * as moment from 'moment';
import { InceptumApp } from 'inceptum';
import BaseApp from 'inceptum/dist/app/BaseApp';
import { EtlBatch, EtlState } from '../../src/EtlBatch';
import { StaticSavepointManager } from '../../src/savepoints/StaticSavepointManager';
import { AdwordsReports } from '../../src/sources/AdwordsReports';
Expand Down Expand Up @@ -168,12 +168,15 @@ suite('AdwordsReports', () => {
});

suite('Test using the plugin to ensure the parameters are passed:', async () => {
const app = new InceptumApp();
const app = new BaseApp();
const context = app.getContext();
const pluginObj = new SourcePlugin('test_12');
app.use(pluginObj);
await app.start();
const source = await context.getObjectByName('EtlSource');
let source: any;
before('start', async () => {
app.use(pluginObj);
await app.start();
source = await context.getObjectByName('EtlSource');
});

test('Test the type of object:', async () => {
source.must.be.instanceof(AdwordsReports);
Expand Down Expand Up @@ -204,5 +207,9 @@ suite('AdwordsReports', () => {
version: 'v201705',
});
});

after('stop', async () => {
await app.stop();
});
});
});
Loading

0 comments on commit 27da705

Please sign in to comment.