Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
471b5ef
ci: add github actions workflow
caiquecastro May 4, 2023
9e5b5e3
build: update sqlite dependency
caiquecastro May 4, 2023
c6802d6
fix: adjust dependencies conflicts
caiquecastro May 4, 2023
4145c8e
style: fix lint errors
caiquecastro May 4, 2023
0d74a8c
build: add postgres service on workflow
caiquecastro May 4, 2023
f545973
ci: expose port for postgres
caiquecastro May 4, 2023
4423199
test: fix database host on CI
caiquecastro May 5, 2023
9637611
ci: configure mysql database
caiquecastro May 5, 2023
c6222a6
ci: configure mssql database
caiquecastro May 5, 2023
5440c3a
ci: wait for mysql to be ready
caiquecastro May 5, 2023
b394144
ci: start mssql before mysql
caiquecastro May 5, 2023
d1668df
ci: add health check for mssql
caiquecastro May 5, 2023
d31b064
ci: expose mysql port
caiquecastro May 5, 2023
e5f0656
test: run mysql on localhost on ci
caiquecastro May 5, 2023
2588906
ci: use bitname image for mysql
caiquecastro May 6, 2023
2015ed0
test: use localhost for postgres connection test
caiquecastro May 6, 2023
313167e
test: fix host for mssql database
caiquecastro May 6, 2023
85213b4
build: update dependencies
caiquecastro May 6, 2023
f2db996
build: convert to esm
caiquecastro May 6, 2023
e0b16c7
fix: move remaining commonjs to esm
caiquecastro May 6, 2023
92b89ff
build: update ava test runner
caiquecastro May 6, 2023
3fb0155
fix: change eslint to use esm
caiquecastro May 6, 2023
93e5d9d
fix: add extension on import esm
caiquecastro May 7, 2023
90122f8
ci: disable lint on CI
caiquecastro May 7, 2023
ee49c09
ci: change password for pg database
caiquecastro May 7, 2023
3d291a2
test: replace msw by nock
caiquecastro May 7, 2023
574c9c1
test: remove nock usage
caiquecastro May 7, 2023
e16aee2
wip
caiquecastro May 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,3 @@ jobs:

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: npm ci

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

- run: npm run lint

- run: npm test
14 changes: 13 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
{
"extends": "airbnb-base"
"env": {
"es2021": true,
"node": true
},
"extends": "airbnb-base",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
}
76 changes: 76 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Node.js CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 19.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

services:
mssql:
image: mcr.microsoft.com/mssql/server
env:
ACCEPT_EULA: Y
SA_PASSWORD: integrator!23
ports:
- 1433:1433
options: >-
--name=mssql
--health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'integrator!23' -Q 'SELECT 1'"
--health-interval=10s
--health-timeout=5s
--health-retries=3

postgres:
image: postgres
env:
POSTGRES_USER: integrator
POSTGRES_DB: integrator
POSTGRES_PASSWORD: integrator!23
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mysql:
image: bitnami/mysql:8.0.33
env:
MYSQL_ROOT_PASSWORD: integrator!23
MYSQL_USER: integrator
MYSQL_PASSWORD: integrator
MYSQL_DATABASE: integrator
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 10

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci
# - name: Lint code
# run: npm run lint
- name: Run tests
run: npm test
10 changes: 5 additions & 5 deletions __tests__/AdapterFactory.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const test = require('ava');
const CsvAdapter = require('../src/Adapters/Csv');
const HttpAdapter = require('../src/Adapters/Http');
const AdapterFactory = require('../src/AdapterFactory');
const DatabaseAdapter = require('../src/Adapters/Database');
import test from 'ava';
import CsvAdapter from '../src/Adapters/Csv.js';
import HttpAdapter from '../src/Adapters/Http.js';
import AdapterFactory from '../src/AdapterFactory.js';
import DatabaseAdapter from '../src/Adapters/Database.js';

test('It creates database adapter', async (t) => {
const adapter = AdapterFactory({
Expand Down
12 changes: 6 additions & 6 deletions __tests__/Adapters/Csv.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fs = require('fs');
const del = require('del');
const test = require('ava');
const path = require('path');
const Csv = require('../../src/Adapters/Csv');
import fs from 'fs';
import { deleteAsync } from 'del';
import test from 'ava';
import path from 'path';
import Csv from '../../src/Adapters/Csv.js';

test.before(() => fs.mkdirSync('./__tests__/fixtures/tmp'));
test.afterEach(() => del('./__tests__/fixtures/tmp'));
test.afterEach(() => deleteAsync('./__tests__/fixtures/tmp'));

test('Requires argument for Csv Adapter', async (t) => {
try {
Expand Down
32 changes: 16 additions & 16 deletions __tests__/Adapters/Database.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('ava');
const manyRows = require('../fixtures/manyRows');
const Database = require('../../src/Adapters/Database');
import test from 'ava';
import manyRows from '../fixtures/manyRows.json' assert { type: 'json' };
import Database from '../../src/Adapters/Database.js';

function createDummyTable(connection) {
return connection.schema.hasTable('Users')
Expand All @@ -21,7 +21,7 @@ function createDummyTable(connection) {
test('It validates the database dialect', async (t) => {
try {
const adapter = new Database({
dialect: 'invalid',
client: 'invalid',
});

await adapter.fetch();
Expand All @@ -34,7 +34,7 @@ test('It validates the database dialect', async (t) => {

test.serial('It fetches from sql server database', async (t) => {
const adapter = new Database({
dialect: 'mssql',
client: 'mssql',
connection: {
host: 'localhost',
user: 'sa',
Expand All @@ -55,12 +55,12 @@ test.serial('It fetches from sql server database', async (t) => {

test('It fetches from mysql database', async (t) => {
const adapter = new Database({
dialect: 'mysql',
client: 'mysql',
connection: {
host: 'localhost',
host: '127.0.0.1',
user: 'integrator',
password: 'integrator!23',
database: 'Integrator',
password: 'integrator',
database: 'integrator',
},
table: 'Users',
});
Expand All @@ -74,12 +74,12 @@ test('It fetches from mysql database', async (t) => {

test('It fetches from postgres database', async (t) => {
const adapter = new Database({
dialect: 'pg',
client: 'pg',
connection: {
host: 'localhost',
host: '127.0.0.1',
user: 'integrator',
password: 'integrator!23',
database: 'Integrator',
database: 'integrator',
},
table: 'Users',
});
Expand All @@ -93,7 +93,7 @@ test('It fetches from postgres database', async (t) => {

test('It fetches the records', async (t) => {
const databaseAdapter = new Database({
dialect: 'sqlite',
client: 'sqlite',
connection: ':memory:',
table: 'Users',
});
Expand All @@ -115,7 +115,7 @@ test('It fetches the records', async (t) => {

test('It fetches specified columns for the records', async (t) => {
const databaseAdapter = new Database({
dialect: 'sqlite',
client: 'sqlite',
connection: ':memory:',
table: 'Users',
columns: [
Expand Down Expand Up @@ -144,7 +144,7 @@ test('It fetches specified columns for the records', async (t) => {

test('It writes the records', async (t) => {
const databaseAdapter = new Database({
dialect: 'sqlite',
client: 'sqlite',
connection: ':memory:',
table: 'Users',
});
Expand All @@ -170,7 +170,7 @@ test('It writes the records', async (t) => {

test.serial('It writes in chunks on sql server database', async (t) => {
const adapter = new Database({
dialect: 'mssql',
client: 'mssql',
connection: {
host: 'localhost',
user: 'sa',
Expand Down
51 changes: 29 additions & 22 deletions __tests__/Adapters/Http.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const test = require('ava');
const nock = require('nock');
const Http = require('../../src/Adapters/Http');
import test from 'ava';
import { rest } from 'msw';
import server from '../fixtures/server.js';
import Http from '../../src/Adapters/Http.js';

test.before(() => server.listen());

// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
test.afterEach(() => server.resetHandlers());

// Clean up after the tests are finished.
test.after(() => server.close());

test('It requires url to fetch', async (t) => {
try {
Expand All @@ -21,13 +31,15 @@ test('It fetches the records', async (t) => {
url: 'https://jsonplaceholder.typicode.com/users',
});

nock('https://jsonplaceholder.typicode.com')
.get('/users')
.reply(200, [{
id: 1,
name: 'John Doe',
email: 'johndoe@example.com',
}]);
server.use(
rest.get('https://jsonplaceholder.typicode.com/users', (req, res, ctx) => res(
ctx.json([{
id: 1,
name: 'John Doe',
email: 'johndoe@example.com',
}]),
)),
);

const result = await adapter.fetch();

Expand All @@ -45,22 +57,17 @@ test('It writes the records', async (t) => {
url: 'https://jsonplaceholder.typicode.com/users',
});

let requestCount = 0;

nock('https://jsonplaceholder.typicode.com')
.post('/users')
.reply(201, (_, requestBody) => {
requestCount += 1;

return requestBody;
});

await adapter.write([
const result = await adapter.write([
{
name: 'John',
email: 'johndoe@example.com',
},
]);

t.is(requestCount, 1);
t.deepEqual(result, [
{
name: 'John',
email: 'johndoe@example.com',
},
]);
});
4 changes: 2 additions & 2 deletions __tests__/Integrator.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require('ava');
const Integrator = require('../src/Integrator');
import test from 'ava';
import Integrator from '../src/Integrator.js';

test('It requires source and destination', async (t) => {
try {
Expand Down
16 changes: 16 additions & 0 deletions __tests__/fixtures/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { rest } from 'msw';
import { setupServer } from 'msw/node';

const handlers = [
rest.post('https://jsonplaceholder.typicode.com/users', (req, res, ctx) => res(
ctx.json({
id: 1,
name: 'John Doe',
email: 'johndoe@example.com',
}),
)),
];

const server = setupServer(...handlers);

export default server;
4 changes: 2 additions & 2 deletions argv.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const yargs = require('yargs');
import yargs from 'yargs';

module.exports = yargs
export default yargs
.option('settings')
.demandOption(['settings'])
.argv;
10 changes: 5 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node
const argv = require('./argv');
const Integrator = require('./src/Integrator');
const SettingsParser = require('./src/SettingsParser');
import argv from './argv';
import Integrator from './src/Integrator';
import SettingsParser from './src/SettingsParser';

(async () => {
const integrator = new Integrator(SettingsParser.parse(argv.settings));

await integrator.run();
})().then(() => {
console.log('Integration finished');
process.stdout.write('Integration finished');
process.exit(0);
}).catch((err) => {
console.error('Integration failed', err);
process.stderr.write(`Integration failed ${err.message}`);
process.exit(1);
});
Loading