mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
fix(graphql): transform types on read in google sheet delete one, append tests
This commit is contained in:
parent
6591fda0b1
commit
13b782eaf6
@ -35,6 +35,24 @@ test('googleSheetAppendMany, one row', async () => {
|
||||
connection: {},
|
||||
});
|
||||
expect(res).toEqual({ insertedCount: 1 });
|
||||
expect(mockAddRows.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
Array [
|
||||
Object {
|
||||
"age": "34",
|
||||
"birth_date": "2020/04/26",
|
||||
"id": "1",
|
||||
"married": "TRUE",
|
||||
"name": "John",
|
||||
},
|
||||
],
|
||||
Object {
|
||||
"raw": undefined,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('googleSheetAppendMany, two rows', async () => {
|
||||
@ -49,6 +67,31 @@ test('googleSheetAppendMany, two rows', async () => {
|
||||
connection: {},
|
||||
});
|
||||
expect(res).toEqual({ insertedCount: 2 });
|
||||
expect(mockAddRows.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
Array [
|
||||
Object {
|
||||
"age": "34",
|
||||
"birth_date": "2020/04/26",
|
||||
"id": "1",
|
||||
"married": "TRUE",
|
||||
"name": "John",
|
||||
},
|
||||
Object {
|
||||
"age": "34",
|
||||
"birth_date": "2020/04/26",
|
||||
"id": "2",
|
||||
"married": "TRUE",
|
||||
"name": "Peter",
|
||||
},
|
||||
],
|
||||
Object {
|
||||
"raw": undefined,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('googleSheetAppendMany, rows empty array', async () => {
|
||||
@ -60,6 +103,16 @@ test('googleSheetAppendMany, rows empty array', async () => {
|
||||
connection: {},
|
||||
});
|
||||
expect(res).toEqual({ insertedCount: 0 });
|
||||
expect(mockAddRows.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
Array [],
|
||||
Object {
|
||||
"raw": undefined,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('googleSheetAppendMany, transform types', async () => {
|
||||
@ -86,6 +139,56 @@ test('googleSheetAppendMany, transform types', async () => {
|
||||
},
|
||||
});
|
||||
expect(res).toEqual({ insertedCount: 1 });
|
||||
expect(mockAddRows.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
Array [
|
||||
Object {
|
||||
"age": "34",
|
||||
"birth_date": "2020-04-26T00:00:00.000Z",
|
||||
"id": "1",
|
||||
"married": "TRUE",
|
||||
"name": "John",
|
||||
},
|
||||
],
|
||||
Object {
|
||||
"raw": undefined,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('googleSheetAppendMany, one row, raw true', async () => {
|
||||
mockAddRows.mockImplementation(mockAddRowsDefaultImp);
|
||||
const res = await resolver({
|
||||
request: {
|
||||
rows: [{ id: '1', name: 'John', age: '34', birth_date: '2020/04/26', married: 'TRUE' }],
|
||||
options: {
|
||||
raw: true,
|
||||
},
|
||||
},
|
||||
connection: {},
|
||||
});
|
||||
expect(res).toEqual({ insertedCount: 1 });
|
||||
expect(mockAddRows.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
Array [
|
||||
Object {
|
||||
"age": "34",
|
||||
"birth_date": "2020/04/26",
|
||||
"id": "1",
|
||||
"married": "TRUE",
|
||||
"name": "John",
|
||||
},
|
||||
],
|
||||
Object {
|
||||
"raw": true,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('valid request schema', () => {
|
||||
|
@ -44,6 +44,22 @@ test('googleSheetAppendOne', async () => {
|
||||
married: 'TRUE',
|
||||
},
|
||||
});
|
||||
expect(mockAddRow.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
Object {
|
||||
"age": "34",
|
||||
"birth_date": "2020/04/26",
|
||||
"id": "1",
|
||||
"married": "TRUE",
|
||||
"name": "John",
|
||||
},
|
||||
Object {
|
||||
"raw": undefined,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('googleSheetAppendOne, transform types', async () => {
|
||||
@ -77,6 +93,61 @@ test('googleSheetAppendOne, transform types', async () => {
|
||||
married: 'TRUE',
|
||||
},
|
||||
});
|
||||
expect(mockAddRow.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
Object {
|
||||
"age": "34",
|
||||
"birth_date": "2020-04-26T00:00:00.000Z",
|
||||
"id": "1",
|
||||
"married": "TRUE",
|
||||
"name": "John",
|
||||
},
|
||||
Object {
|
||||
"raw": undefined,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('googleSheetAppendOne, raw true', async () => {
|
||||
mockAddRow.mockImplementation(mockAddRowDefaultImp);
|
||||
const res = await resolver({
|
||||
request: {
|
||||
row: { id: '1', name: 'John', age: '34', birth_date: '2020/04/26', married: 'TRUE' },
|
||||
options: {
|
||||
raw: true,
|
||||
},
|
||||
},
|
||||
connection: {},
|
||||
});
|
||||
expect(res).toEqual({
|
||||
insertedCount: 1,
|
||||
row: {
|
||||
id: '1',
|
||||
name: 'John',
|
||||
age: '34',
|
||||
birth_date: '2020/04/26',
|
||||
married: 'TRUE',
|
||||
},
|
||||
});
|
||||
expect(mockAddRow.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
Object {
|
||||
"age": "34",
|
||||
"birth_date": "2020/04/26",
|
||||
"id": "1",
|
||||
"married": "TRUE",
|
||||
"name": "John",
|
||||
},
|
||||
Object {
|
||||
"raw": true,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('valid request schema', () => {
|
||||
|
@ -17,6 +17,7 @@
|
||||
import schema from './GoogleSheetDeleteOneSchema.json';
|
||||
import cleanRows from '../cleanRows';
|
||||
import getSheet from '../getSheet';
|
||||
import { transformRead } from '../transformTypes';
|
||||
import mingoFilter from '../../../utils/mingoFilter';
|
||||
|
||||
async function googleSheetDeleteOne({ request, connection }) {
|
||||
@ -24,6 +25,7 @@ async function googleSheetDeleteOne({ request, connection }) {
|
||||
const { limit, skip } = options;
|
||||
const sheet = await getSheet({ connection });
|
||||
let rows = await sheet.getRows({ limit, offset: skip });
|
||||
rows = transformRead({ input: rows, types: connection.columnTypes });
|
||||
rows = mingoFilter({ input: rows, filter });
|
||||
if (rows.length === 0) {
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user