Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 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
a461aee
refactor: use native node test runner
caiquecastro May 13, 2023
2003f33
refactor: change script to test
caiquecastro May 13, 2023
b4bdca8
fix: change password for mysql db
caiquecastro May 13, 2023
2d2d5b4
fix: close db connection after tests
caiquecastro May 13, 2023
b16c118
fix: change typo
caiquecastro May 13, 2023
0ff03ae
fix: parse json file fixture
caiquecastro May 14, 2023
d50c42e
style: fix lint
caiquecastro May 14, 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
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": {
"es2022": 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!23
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
38 changes: 0 additions & 38 deletions __tests__/AdapterFactory.spec.js

This file was deleted.

41 changes: 41 additions & 0 deletions __tests__/AdapterFactory.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
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';

describe('Adapter Factory', () => {
it('It creates database adapter', async () => {
const adapter = AdapterFactory({
type: 'database',
options: {
client: 'sqlite',
},
});

assert.equal(adapter instanceof DatabaseAdapter, true);
});

it('It creates csv adapter', async () => {
const adapter = AdapterFactory({
type: 'csv',
options: {
path: 'my-fake-file',
},
});

assert.equal(adapter instanceof CsvAdapter, true);
});

it('It creates http adapter', async () => {
const adapter = AdapterFactory({
type: 'http',
options: {
url: 'http://api.com/users',
},
});

assert.equal(adapter instanceof HttpAdapter, true);
});
});
79 changes: 0 additions & 79 deletions __tests__/Adapters/Csv.spec.js

This file was deleted.

84 changes: 84 additions & 0 deletions __tests__/Adapters/Csv.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import fs from 'node:fs';
import {
describe, it, beforeEach, afterEach,
} from 'node:test';
import assert from 'node:assert';
import path from 'path';
import Csv from '../../src/Adapters/Csv.js';

function deleteDir(pathName) {
fs.rmSync(path.resolve(pathName), { recursive: true, force: true });
}

describe('Csv Adapter', () => {
beforeEach(() => {
deleteDir('./__tests__/fixtures/tmp');
fs.mkdirSync(path.resolve('./__tests__/fixtures/tmp'));
});
afterEach(() => deleteDir('./__tests__/fixtures/tmp'));

it('Requires argument for Csv Adapter', () => {
assert.throws(() => {
const adapter = new Csv();
assert.ok(adapter);
}, new Error('It\'s required to provide options for the integration'));
});

it('Requires path on options for Csv Adapter', async () => {
assert.throws(() => {
const adapter = new Csv({
//
});
assert.ok(adapter);
}, new Error('It\'s required to provide a file for the csv file'));
});

it('It fetches the records', async () => {
const adapter = new Csv({
path: path.resolve('./__tests__/fixtures/users.csv'),
});

const result = await adapter.fetch();

assert.deepEqual(result, [
{
name: 'John',
email: 'johndoe@example.com',
},
]);
});

it('It fetches specified columns for the records', async () => {
const adapter = new Csv({
path: path.resolve('./__tests__/fixtures/users.csv'),
columns: [
'email',
],
});

const result = await adapter.fetch();

assert.deepEqual(result, [
{
email: 'johndoe@example.com',
},
]);
});

it('It writes the records', async () => {
const adapter = new Csv({
path: path.resolve('./__tests__/fixtures/tmp/users.csv'),
});

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

const result = fs.readFileSync(path.resolve('./__tests__/fixtures/tmp/users.csv'), 'utf-8');

assert.deepEqual(result, 'name;email\nJohn;johndoe@example.com\n');
});
});
Loading