ci: Enable Prettier for /nodes-base (#3315)

*  Extend `.prettierignore` patterns

* 🎨 Apply Prettier to `/src` and `/test`

* 🎨 Update `.prettierignore`

* ✏️ Group dirs with same nesting level

* ✏️ Alphabetize credentials
This commit is contained in:
Iván Ovejero
2022-06-20 23:51:01 +02:00
committed by GitHub
parent a2f628927d
commit 4dac848758
5 changed files with 631 additions and 48 deletions

View File

@@ -1,9 +1,9 @@
const PostgresFun = require('../../../nodes/Postgres/Postgres.node.functions')
const PostgresFun = require('../../../nodes/Postgres/Postgres.node.functions');
const pgPromise = require('pg-promise');
describe('pgUpdate', () => {
it('runs query to update db', async () => {
const updateItem = {id: 1234, name: 'test'};
const updateItem = { id: 1234, name: 'test' };
const nodeParams = {
table: 'mytable',
schema: 'myschema',
@@ -15,21 +15,23 @@ describe('pgUpdate', () => {
const getNodeParam = (key) => nodeParams[key];
const pgp = pgPromise();
const any = jest.fn();
const db = {any};
const db = { any };
const items = [
{
json: updateItem
}
json: updateItem,
},
];
await PostgresFun.pgUpdate(getNodeParam, pgp, db, items)
await PostgresFun.pgUpdate(getNodeParam, pgp, db, items);
expect(db.any).toHaveBeenCalledWith(`update \"myschema\".\"mytable\" as t set \"id\"=v.\"id\",\"name\"=v.\"name\" from (values(1234,'test')) as v(\"id\",\"name\") WHERE v.\"id\" = t.\"id\" RETURNING *`);
expect(db.any).toHaveBeenCalledWith(
`update \"myschema\".\"mytable\" as t set \"id\"=v.\"id\",\"name\"=v.\"name\" from (values(1234,'test')) as v(\"id\",\"name\") WHERE v.\"id\" = t.\"id\" RETURNING *`,
);
});
it('runs query to update db if updateKey is not in columns', async () => {
const updateItem = {id: 1234, name: 'test'};
const updateItem = { id: 1234, name: 'test' };
const nodeParams = {
table: 'mytable',
schema: 'myschema',
@@ -41,21 +43,23 @@ describe('pgUpdate', () => {
const getNodeParam = (key) => nodeParams[key];
const pgp = pgPromise();
const any = jest.fn();
const db = {any};
const db = { any };
const items = [
{
json: updateItem
}
json: updateItem,
},
];
const results = await PostgresFun.pgUpdate(getNodeParam, pgp, db, items)
const results = await PostgresFun.pgUpdate(getNodeParam, pgp, db, items);
expect(db.any).toHaveBeenCalledWith(`update \"myschema\".\"mytable\" as t set \"id\"=v.\"id\",\"name\"=v.\"name\" from (values(1234,'test')) as v(\"id\",\"name\") WHERE v.\"id\" = t.\"id\" RETURNING *`);
expect(db.any).toHaveBeenCalledWith(
`update \"myschema\".\"mytable\" as t set \"id\"=v.\"id\",\"name\"=v.\"name\" from (values(1234,'test')) as v(\"id\",\"name\") WHERE v.\"id\" = t.\"id\" RETURNING *`,
);
});
it('runs query to update db with cast as updateKey', async () => {
const updateItem = {id: '1234', name: 'test'};
const updateItem = { id: '1234', name: 'test' };
const nodeParams = {
table: 'mytable',
schema: 'myschema',
@@ -67,21 +71,23 @@ describe('pgUpdate', () => {
const getNodeParam = (key) => nodeParams[key];
const pgp = pgPromise();
const any = jest.fn();
const db = {any};
const db = { any };
const items = [
{
json: updateItem
}
json: updateItem,
},
];
await PostgresFun.pgUpdate(getNodeParam, pgp, db, items)
await PostgresFun.pgUpdate(getNodeParam, pgp, db, items);
expect(db.any).toHaveBeenCalledWith(`update \"myschema\".\"mytable\" as t set \"id\"=v.\"id\",\"name\"=v.\"name\" from (values('1234'::uuid,'test')) as v(\"id\",\"name\") WHERE v.\"id\" = t.\"id\" RETURNING *`);
expect(db.any).toHaveBeenCalledWith(
`update \"myschema\".\"mytable\" as t set \"id\"=v.\"id\",\"name\"=v.\"name\" from (values('1234'::uuid,'test')) as v(\"id\",\"name\") WHERE v.\"id\" = t.\"id\" RETURNING *`,
);
});
it('runs query to update db with cast in target columns', async () => {
const updateItem = {id: '1234', name: 'test'};
const updateItem = { id: '1234', name: 'test' };
const nodeParams = {
table: 'mytable',
schema: 'myschema',
@@ -93,25 +99,25 @@ describe('pgUpdate', () => {
const getNodeParam = (key) => nodeParams[key];
const pgp = pgPromise();
const any = jest.fn();
const db = {any};
const db = { any };
const items = [
{
json: updateItem
}
json: updateItem,
},
];
await PostgresFun.pgUpdate(getNodeParam, pgp, db, items)
await PostgresFun.pgUpdate(getNodeParam, pgp, db, items);
expect(db.any).toHaveBeenCalledWith(`update \"myschema\".\"mytable\" as t set \"id\"=v.\"id\",\"name\"=v.\"name\" from (values('1234'::uuid,'test')) as v(\"id\",\"name\") WHERE v.\"id\" = t.\"id\" RETURNING *`);
expect(db.any).toHaveBeenCalledWith(
`update \"myschema\".\"mytable\" as t set \"id\"=v.\"id\",\"name\"=v.\"name\" from (values('1234'::uuid,'test')) as v(\"id\",\"name\") WHERE v.\"id\" = t.\"id\" RETURNING *`,
);
});
});
describe('pgInsert', () => {
it('runs query to insert', async () => {
const insertItem = {id: 1234, name: 'test', age: 34};
const insertItem = { id: 1234, name: 'test', age: 34 };
const nodeParams = {
table: 'mytable',
schema: 'myschema',
@@ -122,7 +128,7 @@ describe('pgInsert', () => {
const getNodeParam = (key) => nodeParams[key];
const pgp = pgPromise();
const any = jest.fn();
const db = {any};
const db = { any };
const items = [
{
@@ -132,11 +138,13 @@ describe('pgInsert', () => {
await PostgresFun.pgInsert(getNodeParam, pgp, db, items);
expect(db.any).toHaveBeenCalledWith(`insert into \"myschema\".\"mytable\"(\"id\",\"name\",\"age\") values(1234,'test',34) RETURNING *`);
expect(db.any).toHaveBeenCalledWith(
`insert into \"myschema\".\"mytable\"(\"id\",\"name\",\"age\") values(1234,'test',34) RETURNING *`,
);
});
it('runs query to insert with type casting', async () => {
const insertItem = {id: 1234, name: 'test', age: 34};
const insertItem = { id: 1234, name: 'test', age: 34 };
const nodeParams = {
table: 'mytable',
schema: 'myschema',
@@ -147,7 +155,7 @@ describe('pgInsert', () => {
const getNodeParam = (key) => nodeParams[key];
const pgp = pgPromise();
const any = jest.fn();
const db = {any};
const db = { any };
const items = [
{
@@ -157,6 +165,8 @@ describe('pgInsert', () => {
await PostgresFun.pgInsert(getNodeParam, pgp, db, items);
expect(db.any).toHaveBeenCalledWith(`insert into \"myschema\".\"mytable\"(\"id\",\"name\",\"age\") values(1234::int,'test'::text,34) RETURNING *`);
expect(db.any).toHaveBeenCalledWith(
`insert into \"myschema\".\"mytable\"(\"id\",\"name\",\"age\") values(1234::int,'test'::text,34) RETURNING *`,
);
});
});