From 8d700655ba66aae7bc4397d1eabd06741fc7b5cf Mon Sep 17 00:00:00 2001 From: Duarte Velez Grilo Date: Wed, 18 Oct 2023 16:06:51 +0100 Subject: [PATCH 01/10] Update manifest.json Added used camera preference option. --- packages/client/manifest.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 8d0a4e456f..f294dbbc80 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -3419,6 +3419,22 @@ "value": "custom" } }, + { + "type": "select", + "label": "Preferred camera", + "key": "preferredCamera", + "defaultValue": "environment", + "options": [ + { + "label": "Front", + "value": "user" + }, + { + "label": "Back", + "value": "environment" + } + ] + }, { "type": "event", "label": "On change", From 5e4821e6a5e22473e869bf71f2499649ae453d26 Mon Sep 17 00:00:00 2001 From: Duarte Velez Grilo Date: Wed, 18 Oct 2023 16:12:12 +0100 Subject: [PATCH 02/10] Update CodeScannerField.svelte Added preferred camera setting. --- .../client/src/components/app/forms/CodeScannerField.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/client/src/components/app/forms/CodeScannerField.svelte b/packages/client/src/components/app/forms/CodeScannerField.svelte index c408f78d7c..1a57d8fbe2 100644 --- a/packages/client/src/components/app/forms/CodeScannerField.svelte +++ b/packages/client/src/components/app/forms/CodeScannerField.svelte @@ -14,6 +14,7 @@ export let beepOnScan export let beepFrequency export let customFrequency + export let preferredCamera let fieldState let fieldApi @@ -48,6 +49,7 @@ {beepOnScan} {beepFrequency} {customFrequency} + {preferredCamera} /> {/if} From ad3a80c629e4748bc1f27bb4193f8912100b9d33 Mon Sep 17 00:00:00 2001 From: Duarte Velez Grilo Date: Wed, 18 Oct 2023 16:13:50 +0100 Subject: [PATCH 03/10] Update CodeScanner.svelte Added preferred camera setting. --- packages/client/src/components/app/forms/CodeScanner.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/app/forms/CodeScanner.svelte b/packages/client/src/components/app/forms/CodeScanner.svelte index 04d6919157..891154939f 100644 --- a/packages/client/src/components/app/forms/CodeScanner.svelte +++ b/packages/client/src/components/app/forms/CodeScanner.svelte @@ -11,6 +11,7 @@ export let beepOnScan = false export let beepFrequency = 2637 export let customFrequency = 1046 + export let preferredCamera = "environment" const dispatch = createEventDispatcher() @@ -20,7 +21,7 @@ let cameraEnabled let cameraStarted = false let html5QrCode - let cameraSetting = { facingMode: "environment" } + let cameraSetting = { facingMode: "{preferredCamera}" } let cameraConfig = { fps: 25, qrbox: { width: 250, height: 250 }, From 92e091818b20113ecc332da17d227ca0247e1217 Mon Sep 17 00:00:00 2001 From: Duarte Velez Grilo Date: Thu, 19 Oct 2023 11:11:10 +0100 Subject: [PATCH 04/10] Update CodeScanner.svelte Removed quotes ("") from variable reference. I believe this is what is causing the test failure. --- packages/client/src/components/app/forms/CodeScanner.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/components/app/forms/CodeScanner.svelte b/packages/client/src/components/app/forms/CodeScanner.svelte index 891154939f..f68f0791f6 100644 --- a/packages/client/src/components/app/forms/CodeScanner.svelte +++ b/packages/client/src/components/app/forms/CodeScanner.svelte @@ -21,7 +21,7 @@ let cameraEnabled let cameraStarted = false let html5QrCode - let cameraSetting = { facingMode: "{preferredCamera}" } + let cameraSetting = { facingMode: {preferredCamera} } let cameraConfig = { fps: 25, qrbox: { width: 250, height: 250 }, From 34a752dd41310ac778f83e7d47117f6f13599df4 Mon Sep 17 00:00:00 2001 From: Duarte Velez Grilo Date: Fri, 20 Oct 2023 12:46:43 +0100 Subject: [PATCH 05/10] Update CodeScanner.svelte Updated the code as suggested. Thanks! --- packages/client/src/components/app/forms/CodeScanner.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/components/app/forms/CodeScanner.svelte b/packages/client/src/components/app/forms/CodeScanner.svelte index f68f0791f6..f2e32004cf 100644 --- a/packages/client/src/components/app/forms/CodeScanner.svelte +++ b/packages/client/src/components/app/forms/CodeScanner.svelte @@ -21,7 +21,7 @@ let cameraEnabled let cameraStarted = false let html5QrCode - let cameraSetting = { facingMode: {preferredCamera} } + let cameraSetting = { facingMode: preferredCamera } let cameraConfig = { fps: 25, qrbox: { width: 250, height: 250 }, From f292e22f83eeae3de99c03f5f4b8f1c7fe8adbe4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 6 Nov 2023 15:07:09 +0100 Subject: [PATCH 06/10] Fix triggering release --- .github/workflows/tag-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml index b413ced3d2..78c07a037c 100644 --- a/.github/workflows/tag-release.yml +++ b/.github/workflows/tag-release.yml @@ -46,7 +46,7 @@ jobs: ./versionCommit.sh $BUMP_TYPE - new_version=$(./scripts/getCurrentVersion.sh) + new_version=$(./getCurrentVersion.sh) echo "version=$new_version" >> $GITHUB_OUTPUT trigger-release: From dbcbb2e6b7680ebb6cfb7d01b1d4663703a35c12 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 6 Nov 2023 15:33:02 +0000 Subject: [PATCH 07/10] Add test to row patch endpoint, it succeeds. Problem must be elsewhere. --- .../server/src/api/routes/tests/row.spec.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 92d581d930..48f7ab4f09 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -563,6 +563,56 @@ describe.each([ await assertRowUsage(rowUsage) await assertQueryUsage(queryUsage) }) + + it("should not overwrite links if those links are not set", async () => { + let linkField: FieldSchema = { + type: FieldType.LINK, + name: "", + fieldName: "", + constraints: { + type: "array", + presence: false, + }, + relationshipType: RelationshipType.ONE_TO_MANY, + tableId: InternalTable.USER_METADATA, + } + + let table = await config.api.table.create({ + name: "TestTable", + type: "table", + sourceType: TableSourceType.INTERNAL, + sourceId: INTERNAL_TABLE_SOURCE_ID, + schema: { + user1: { ...linkField, name: "user1", fieldName: "user1" }, + user2: { ...linkField, name: "user2", fieldName: "user2" }, + }, + }) + + let user1 = await config.createUser() + let user2 = await config.createUser() + + let row = await config.api.row.save(table._id!, { + user1: [{ _id: user1._id }], + user2: [{ _id: user2._id }], + }) + + let getResp = await config.api.row.get(table._id!, row._id!) + expect(getResp.body.user1[0]._id).toEqual(user1._id) + expect(getResp.body.user2[0]._id).toEqual(user2._id) + + let patchResp = await config.api.row.patch(table._id!, { + _id: row._id!, + _rev: row._rev!, + tableId: table._id!, + user1: [{ _id: user2._id }], + }) + expect(patchResp.user1[0]._id).toEqual(user2._id) + expect(patchResp.user2[0]._id).toEqual(user2._id) + + getResp = await config.api.row.get(table._id!, row._id!) + expect(getResp.body.user1[0]._id).toEqual(user2._id) + expect(getResp.body.user2[0]._id).toEqual(user2._id) + }) }) describe("destroy", () => { From b02512fd3c4203b6dc6697b5a6b7500e14612971 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 6 Nov 2023 15:56:58 +0000 Subject: [PATCH 08/10] Create a test of a table with 2 link fields in updateRow.spec.ts. --- .../src/automations/tests/updateRow.spec.js | 44 ------- .../src/automations/tests/updateRow.spec.ts | 107 ++++++++++++++++++ .../src/automations/tests/utilities/index.ts | 6 +- 3 files changed, 110 insertions(+), 47 deletions(-) delete mode 100644 packages/server/src/automations/tests/updateRow.spec.js create mode 100644 packages/server/src/automations/tests/updateRow.spec.ts diff --git a/packages/server/src/automations/tests/updateRow.spec.js b/packages/server/src/automations/tests/updateRow.spec.js deleted file mode 100644 index 77383d80e9..0000000000 --- a/packages/server/src/automations/tests/updateRow.spec.js +++ /dev/null @@ -1,44 +0,0 @@ -const setup = require("./utilities") - -describe("test the update row action", () => { - let table, row, inputs - let config = setup.getConfig() - - beforeAll(async () => { - await config.init() - table = await config.createTable() - row = await config.createRow() - inputs = { - rowId: row._id, - row: { - ...row, - name: "Updated name", - // put a falsy option in to be removed - description: "", - } - } - }) - - afterAll(setup.afterAll) - - it("should be able to run the action", async () => { - const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, inputs) - expect(res.success).toEqual(true) - const updatedRow = await config.getRow(table._id, res.id) - expect(updatedRow.name).toEqual("Updated name") - expect(updatedRow.description).not.toEqual("") - }) - - it("should check invalid inputs return an error", async () => { - const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, {}) - expect(res.success).toEqual(false) - }) - - it("should return an error when table doesn't exist", async () => { - const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, { - row: { _id: "invalid" }, - rowId: "invalid", - }) - expect(res.success).toEqual(false) - }) -}) diff --git a/packages/server/src/automations/tests/updateRow.spec.ts b/packages/server/src/automations/tests/updateRow.spec.ts new file mode 100644 index 0000000000..63925b0d3b --- /dev/null +++ b/packages/server/src/automations/tests/updateRow.spec.ts @@ -0,0 +1,107 @@ +import { + FieldSchema, + FieldType, + INTERNAL_TABLE_SOURCE_ID, + InternalTable, + RelationshipType, + Row, + Table, + TableSourceType, +} from "@budibase/types" + +import * as setup from "./utilities" + +describe("test the update row action", () => { + let table: Table, row: Row, inputs: any + let config = setup.getConfig() + + beforeAll(async () => { + await config.init() + table = await config.createTable() + row = await config.createRow() + inputs = { + rowId: row._id, + row: { + ...row, + name: "Updated name", + // put a falsy option in to be removed + description: "", + }, + } + }) + + afterAll(setup.afterAll) + + it("should be able to run the action", async () => { + const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, inputs) + expect(res.success).toEqual(true) + const updatedRow = await config.getRow(table._id!, res.id) + expect(updatedRow.name).toEqual("Updated name") + expect(updatedRow.description).not.toEqual("") + }) + + it("should check invalid inputs return an error", async () => { + const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, {}) + expect(res.success).toEqual(false) + }) + + it("should return an error when table doesn't exist", async () => { + const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, { + row: { _id: "invalid" }, + rowId: "invalid", + }) + expect(res.success).toEqual(false) + }) + + it("should not overwrite links if those links are not set", async () => { + let linkField: FieldSchema = { + type: FieldType.LINK, + name: "", + fieldName: "", + constraints: { + type: "array", + presence: false, + }, + relationshipType: RelationshipType.ONE_TO_MANY, + tableId: InternalTable.USER_METADATA, + } + + let table = await config.api.table.create({ + name: "TestTable", + type: "table", + sourceType: TableSourceType.INTERNAL, + sourceId: INTERNAL_TABLE_SOURCE_ID, + schema: { + user1: { ...linkField, name: "user1", fieldName: "user1" }, + user2: { ...linkField, name: "user2", fieldName: "user2" }, + }, + }) + + let user1 = await config.createUser() + let user2 = await config.createUser() + + let row = await config.api.row.save(table._id!, { + user1: [{ _id: user1._id }], + user2: [{ _id: user2._id }], + }) + + let getResp = await config.api.row.get(table._id!, row._id!) + expect(getResp.body.user1[0]._id).toEqual(user1._id) + expect(getResp.body.user2[0]._id).toEqual(user2._id) + + let stepResp = await setup.runStep(setup.actions.UPDATE_ROW.stepId, { + rowId: row._id, + row: { + _id: row._id, + _rev: row._rev, + tableId: row.tableId, + user1: [{ _id: user2._id }], + }, + }) + expect(stepResp.success).toEqual(true) + + getResp = await config.api.row.get(table._id!, row._id!) + expect(getResp.body.user1[0]._id).toEqual(user2._id) + expect(getResp.body.user2[0]._id).toEqual(user2._id) + }) +}) diff --git a/packages/server/src/automations/tests/utilities/index.ts b/packages/server/src/automations/tests/utilities/index.ts index 9ba4f950f3..cd3ea289ca 100644 --- a/packages/server/src/automations/tests/utilities/index.ts +++ b/packages/server/src/automations/tests/utilities/index.ts @@ -4,11 +4,11 @@ import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions" import emitter from "../../../events/index" import env from "../../../environment" -let config: any +let config: TestConfig -export function getConfig() { +export function getConfig(): TestConfig { if (!config) { - config = new TestConfig(false) + config = new TestConfig(true) } return config } From 2684b73768ce990b542a7575feeb864b1fbb613c Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 6 Nov 2023 16:40:27 +0000 Subject: [PATCH 09/10] Fix type error. --- packages/server/src/automations/tests/automation.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/automations/tests/automation.spec.ts b/packages/server/src/automations/tests/automation.spec.ts index 67ff6d40ec..c37c9cc7ce 100644 --- a/packages/server/src/automations/tests/automation.spec.ts +++ b/packages/server/src/automations/tests/automation.spec.ts @@ -36,7 +36,7 @@ describe("Run through some parts of the automations system", () => { it("should be able to init in builder", async () => { const automation: Automation = { ...basicAutomation(), - appId: config.appId, + appId: config.appId!, } const fields: any = { a: 1, appId: config.appId } await triggers.externalTrigger(automation, fields) From f21addeb7170f5e83a662e9fb05b6f3d712f8798 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 6 Nov 2023 17:34:30 +0000 Subject: [PATCH 10/10] Add another test to make sure relationships are cleared when asked. --- .../src/automations/tests/updateRow.spec.ts | 70 +++++++++++++++++-- .../server/src/tests/utilities/api/table.ts | 10 ++- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/packages/server/src/automations/tests/updateRow.spec.ts b/packages/server/src/automations/tests/updateRow.spec.ts index 63925b0d3b..7e369f1ecb 100644 --- a/packages/server/src/automations/tests/updateRow.spec.ts +++ b/packages/server/src/automations/tests/updateRow.spec.ts @@ -10,6 +10,7 @@ import { } from "@budibase/types" import * as setup from "./utilities" +import * as uuid from "uuid" describe("test the update row action", () => { let table: Table, row: Row, inputs: any @@ -67,13 +68,13 @@ describe("test the update row action", () => { } let table = await config.api.table.create({ - name: "TestTable", + name: uuid.v4(), type: "table", sourceType: TableSourceType.INTERNAL, sourceId: INTERNAL_TABLE_SOURCE_ID, schema: { - user1: { ...linkField, name: "user1", fieldName: "user1" }, - user2: { ...linkField, name: "user2", fieldName: "user2" }, + user1: { ...linkField, name: "user1", fieldName: uuid.v4() }, + user2: { ...linkField, name: "user2", fieldName: uuid.v4() }, }, }) @@ -95,7 +96,8 @@ describe("test the update row action", () => { _id: row._id, _rev: row._rev, tableId: row.tableId, - user1: [{ _id: user2._id }], + user1: [user2._id], + user2: "", }, }) expect(stepResp.success).toEqual(true) @@ -104,4 +106,64 @@ describe("test the update row action", () => { expect(getResp.body.user1[0]._id).toEqual(user2._id) expect(getResp.body.user2[0]._id).toEqual(user2._id) }) + + it("should overwrite links if those links are not set and we ask it do", async () => { + let linkField: FieldSchema = { + type: FieldType.LINK, + name: "", + fieldName: "", + constraints: { + type: "array", + presence: false, + }, + relationshipType: RelationshipType.ONE_TO_MANY, + tableId: InternalTable.USER_METADATA, + } + + let table = await config.api.table.create({ + name: uuid.v4(), + type: "table", + sourceType: TableSourceType.INTERNAL, + sourceId: INTERNAL_TABLE_SOURCE_ID, + schema: { + user1: { ...linkField, name: "user1", fieldName: uuid.v4() }, + user2: { ...linkField, name: "user2", fieldName: uuid.v4() }, + }, + }) + + let user1 = await config.createUser() + let user2 = await config.createUser() + + let row = await config.api.row.save(table._id!, { + user1: [{ _id: user1._id }], + user2: [{ _id: user2._id }], + }) + + let getResp = await config.api.row.get(table._id!, row._id!) + expect(getResp.body.user1[0]._id).toEqual(user1._id) + expect(getResp.body.user2[0]._id).toEqual(user2._id) + + let stepResp = await setup.runStep(setup.actions.UPDATE_ROW.stepId, { + rowId: row._id, + row: { + _id: row._id, + _rev: row._rev, + tableId: row.tableId, + user1: [user2._id], + user2: "", + }, + meta: { + fields: { + user2: { + clearRelationships: true, + }, + }, + }, + }) + expect(stepResp.success).toEqual(true) + + getResp = await config.api.row.get(table._id!, row._id!) + expect(getResp.body.user1[0]._id).toEqual(user2._id) + expect(getResp.body.user2).toBeUndefined() + }) }) diff --git a/packages/server/src/tests/utilities/api/table.ts b/packages/server/src/tests/utilities/api/table.ts index b80c940697..ffd9e19ee8 100644 --- a/packages/server/src/tests/utilities/api/table.ts +++ b/packages/server/src/tests/utilities/api/table.ts @@ -22,7 +22,15 @@ export class TableAPI extends TestAPI { .send(data) .set(this.config.defaultHeaders()) .expect("Content-Type", /json/) - .expect(expectStatus) + + if (res.status !== expectStatus) { + throw new Error( + `Expected status ${expectStatus} but got ${ + res.status + } with body ${JSON.stringify(res.body)}` + ) + } + return res.body }