From 35c91a75afee5ea1fffbae09635076f7e1705b63 Mon Sep 17 00:00:00 2001 From: cchensh Date: Fri, 27 Sep 2024 12:52:58 -0400 Subject: [PATCH 1/7] Added datastore basic command --- .../src/cli/commands/datastore.spec.ts | 52 ++++++++++++ .../cli-test/src/cli/commands/datastore.ts | 82 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 packages/cli-test/src/cli/commands/datastore.spec.ts create mode 100644 packages/cli-test/src/cli/commands/datastore.ts diff --git a/packages/cli-test/src/cli/commands/datastore.spec.ts b/packages/cli-test/src/cli/commands/datastore.spec.ts new file mode 100644 index 000000000..d335f8c44 --- /dev/null +++ b/packages/cli-test/src/cli/commands/datastore.spec.ts @@ -0,0 +1,52 @@ +import sinon from 'sinon'; + +import { mockProcess } from '../../utils/test'; +import { shell } from '../shell'; +import datastore from './datastore'; + +describe('datastore commands', () => { + const sandbox = sinon.createSandbox(); + let spawnSpy: sinon.SinonStub; + + beforeEach(() => { + const process = mockProcess(); + spawnSpy = sandbox.stub(shell, 'spawnProcess').returns({ + command: 'something', + finished: true, + output: 'hi', + process, + }); + sandbox.stub(shell, 'checkIfFinished').resolves(); + }); + afterEach(() => { + sandbox.restore(); + }); + + describe('put method', () => { + it('should invoke `datastore put [item details]`', async () => { + await datastore.datastorePut({ appPath: '/some/path', putDetails: '{ "datastore": "datastore", "item": { "id": "1"} }' }); + sandbox.assert.calledWith( + spawnSpy, + sinon.match(`datastore put '{ "datastore": "datastore", "item": { "id": "1"} }'`), + ); + }); + }); + describe('get method', () => { + it('should invoke `datastore get `', async () => { + await datastore.datastoreGet({ appPath: '/some/path', getQuery: '{ "datastore": "datastore", "id": "1" }' }); + sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore get '{ "datastore": "datastore", "id": "1" }'`)); + }); + }); + describe('delete method', () => { + it('should invoke `datastore delete `', async () => { + await datastore.datastoreDelete({ appPath: '/some/path', deleteQuery: '{ "datastore": "datastore", "id": "1" }' }); + sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore delete '{ "datastore": "datastore", "id": "1" }'`)); + }); + }); + describe('query method', () => { + it('should invoke `datastore query [expression]`', async () => { + await datastore.datastoreQuery({ appPath: '/some/path', queryExpression: '{ "datastore": "datastore", "expression": "id = :id", "expression_values": {":id": "1"} }' }); + sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore query '{ "datastore": "datastore", "expression": "id = :id", "expression_values": {":id": "1"} }'`)); + }); + }); +}); diff --git a/packages/cli-test/src/cli/commands/datastore.ts b/packages/cli-test/src/cli/commands/datastore.ts new file mode 100644 index 000000000..f97c1ba44 --- /dev/null +++ b/packages/cli-test/src/cli/commands/datastore.ts @@ -0,0 +1,82 @@ +import type { ProjectCommandArguments } from '../../types/commands/common_arguments'; +import { SlackCLIProcess } from '../cli-process'; + +export interface DatastoreCommandArguments { + /** @description datastore get */ + getQuery: string; + /** @description datastore put [item details] */ + putDetails: string; + /** @description datastore query [expression] */ + queryExpression: string; + /** @description datastore delete */ + deleteQuery: string; +} + +/** + * `slack datastore put` + * @returns command output + */ +export const datastorePut = async function datastorePut( + args: ProjectCommandArguments & Pick, +): Promise { + const cmd = new SlackCLIProcess( + `datastore put '${args.putDetails}'`, + args, + ); + const proc = await cmd.execAsync({ + cwd: args.appPath, + }); + return proc.output; +}; + +/** + * `slack datastore get` + * @returns command output + */ +export const datastoreGet = async function datastoreGet( + args: ProjectCommandArguments & Pick, +): Promise { + const cmd = new SlackCLIProcess(`datastore get '${args.getQuery}'`, args); + const proc = await cmd.execAsync({ + cwd: args.appPath, + }); + return proc.output; +}; + +/** + * `slack datastore delete` + * @returns command output + */ +export const datastoreDelete = async function datastoreDelete( + args: ProjectCommandArguments & Pick, +): Promise { + const cmd = new SlackCLIProcess(`datastore delete '${args.deleteQuery}'`, args); + const proc = await cmd.execAsync({ + cwd: args.appPath, + }); + return proc.output; +}; + +/** + * `slack datastore query` + * @returns command output + */ +export const datastoreQuery = async function datastoreQuery( + args: ProjectCommandArguments & Pick, +): Promise { + const cmd = new SlackCLIProcess( + `datastore query '${args.queryExpression}'`, + args, + ); + const proc = await cmd.execAsync({ + cwd: args.appPath, + }); + return proc.output; +}; + +export default { + datastorePut, + datastoreGet, + datastoreDelete, + datastoreQuery, +}; From 1198cef8ac04298238a68da5ebdd57657ee12f2c Mon Sep 17 00:00:00 2001 From: cchensh Date: Fri, 27 Sep 2024 16:13:22 -0400 Subject: [PATCH 2/7] Updated with proper way to model the data --- .../src/cli/commands/datastore.spec.ts | 30 ++++---- .../cli-test/src/cli/commands/datastore.ts | 69 ++++++++++++------- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/packages/cli-test/src/cli/commands/datastore.spec.ts b/packages/cli-test/src/cli/commands/datastore.spec.ts index d335f8c44..9e8d8bddb 100644 --- a/packages/cli-test/src/cli/commands/datastore.spec.ts +++ b/packages/cli-test/src/cli/commands/datastore.spec.ts @@ -22,31 +22,31 @@ describe('datastore commands', () => { sandbox.restore(); }); - describe('put method', () => { - it('should invoke `datastore put [item details]`', async () => { - await datastore.datastorePut({ appPath: '/some/path', putDetails: '{ "datastore": "datastore", "item": { "id": "1"} }' }); - sandbox.assert.calledWith( - spawnSpy, - sinon.match(`datastore put '{ "datastore": "datastore", "item": { "id": "1"} }'`), - ); - }); - }); describe('get method', () => { it('should invoke `datastore get `', async () => { - await datastore.datastoreGet({ appPath: '/some/path', getQuery: '{ "datastore": "datastore", "id": "1" }' }); - sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore get '{ "datastore": "datastore", "id": "1" }'`)); + await datastore.datastoreGet({ appPath: '/some/path', datastoreName: 'datastore', primaryKeyValue: '1' }); + sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore get`)); }); }); describe('delete method', () => { it('should invoke `datastore delete `', async () => { - await datastore.datastoreDelete({ appPath: '/some/path', deleteQuery: '{ "datastore": "datastore", "id": "1" }' }); - sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore delete '{ "datastore": "datastore", "id": "1" }'`)); + await datastore.datastoreDelete({ appPath: '/some/path', datastoreName: 'datastore', primaryKeyValue: '1' }); + sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore delete`)); + }); + }); + describe('put method', () => { + it('should invoke `datastore put [item details]`', async () => { + await datastore.datastorePut({ appPath: '/some/path', datastoreName: 'datastore', putItem: '{ "id": "1"}' }); + sandbox.assert.calledWith( + spawnSpy, + sinon.match(`datastore put`), + ); }); }); describe('query method', () => { it('should invoke `datastore query [expression]`', async () => { - await datastore.datastoreQuery({ appPath: '/some/path', queryExpression: '{ "datastore": "datastore", "expression": "id = :id", "expression_values": {":id": "1"} }' }); - sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore query '{ "datastore": "datastore", "expression": "id = :id", "expression_values": {":id": "1"} }'`)); + await datastore.datastoreQuery({ appPath: '/some/path', datastoreName: 'datastore', queryExpression: 'id = :id', queryExpressionValues: '{ ":id": "1"}'}); + sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore query`)); }); }); }); diff --git a/packages/cli-test/src/cli/commands/datastore.ts b/packages/cli-test/src/cli/commands/datastore.ts index f97c1ba44..8d0d4abde 100644 --- a/packages/cli-test/src/cli/commands/datastore.ts +++ b/packages/cli-test/src/cli/commands/datastore.ts @@ -2,27 +2,31 @@ import type { ProjectCommandArguments } from '../../types/commands/common_argume import { SlackCLIProcess } from '../cli-process'; export interface DatastoreCommandArguments { - /** @description datastore get */ - getQuery: string; + /** @description datastore name */ + datastoreName: string; + /** @description datastore get primary key value*/ + primaryKeyValue: string; /** @description datastore put [item details] */ - putDetails: string; + putItem: string; /** @description datastore query [expression] */ queryExpression: string; - /** @description datastore delete */ - deleteQuery: string; + /** @description datastore query [expression expression_values] */ + queryExpressionValues: string; } /** - * `slack datastore put` + * `slack datastore get` * @returns command output */ -export const datastorePut = async function datastorePut( - args: ProjectCommandArguments & Pick, +export const datastoreGet = async function datastoreGet( + args: ProjectCommandArguments & Pick, ): Promise { - const cmd = new SlackCLIProcess( - `datastore put '${args.putDetails}'`, - args, - ); + const getQueryObj: any = { + datastore: args.datastoreName, + id: args.primaryKeyValue + }; + const getQuery = JSON.stringify(getQueryObj); + const cmd = new SlackCLIProcess(`datastore get ${getQuery}`, args); const proc = await cmd.execAsync({ cwd: args.appPath, }); @@ -30,13 +34,18 @@ export const datastorePut = async function datastorePut( }; /** - * `slack datastore get` + * `slack datastore delete` * @returns command output */ -export const datastoreGet = async function datastoreGet( - args: ProjectCommandArguments & Pick, +export const datastoreDelete = async function datastoreDelete( + args: ProjectCommandArguments & Pick, ): Promise { - const cmd = new SlackCLIProcess(`datastore get '${args.getQuery}'`, args); + const deleteQueryObj: any = { + datastore: args.datastoreName, + id: args.primaryKeyValue + }; + const deleteQuery = JSON.stringify(deleteQueryObj); + const cmd = new SlackCLIProcess(`datastore delete '${deleteQuery}'`, args); const proc = await cmd.execAsync({ cwd: args.appPath, }); @@ -44,13 +53,21 @@ export const datastoreGet = async function datastoreGet( }; /** - * `slack datastore delete` + * `slack datastore put` * @returns command output */ -export const datastoreDelete = async function datastoreDelete( - args: ProjectCommandArguments & Pick, +export const datastorePut = async function datastorePut( + args: ProjectCommandArguments & Pick, ): Promise { - const cmd = new SlackCLIProcess(`datastore delete '${args.deleteQuery}'`, args); + const putQueryObj: any = { + datastore: args.datastoreName, + item: args.putItem + }; + const putQuery = JSON.stringify(putQueryObj); + const cmd = new SlackCLIProcess( + `datastore put '${putQuery}'`, + args, + ); const proc = await cmd.execAsync({ cwd: args.appPath, }); @@ -62,10 +79,16 @@ export const datastoreDelete = async function datastoreDelete( * @returns command output */ export const datastoreQuery = async function datastoreQuery( - args: ProjectCommandArguments & Pick, + args: ProjectCommandArguments & Pick, ): Promise { + const queryObj: any = { + datastore: args.datastoreName, + expression: args.queryExpression, + expression_values: args.queryExpressionValues + }; + const query = JSON.stringify(queryObj); const cmd = new SlackCLIProcess( - `datastore query '${args.queryExpression}'`, + `datastore query '${query}'`, args, ); const proc = await cmd.execAsync({ @@ -75,8 +98,8 @@ export const datastoreQuery = async function datastoreQuery( }; export default { - datastorePut, datastoreGet, datastoreDelete, + datastorePut, datastoreQuery, }; From b47b70a9f16cb3ef4a7dbb4c22ce6544cf868215 Mon Sep 17 00:00:00 2001 From: cchensh Date: Fri, 27 Sep 2024 16:21:11 -0400 Subject: [PATCH 3/7] updated data type --- packages/cli-test/src/cli/commands/datastore.spec.ts | 11 +++++++++-- packages/cli-test/src/cli/commands/datastore.ts | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/cli-test/src/cli/commands/datastore.spec.ts b/packages/cli-test/src/cli/commands/datastore.spec.ts index 9e8d8bddb..41f0b0720 100644 --- a/packages/cli-test/src/cli/commands/datastore.spec.ts +++ b/packages/cli-test/src/cli/commands/datastore.spec.ts @@ -36,7 +36,11 @@ describe('datastore commands', () => { }); describe('put method', () => { it('should invoke `datastore put [item details]`', async () => { - await datastore.datastorePut({ appPath: '/some/path', datastoreName: 'datastore', putItem: '{ "id": "1"}' }); + const itemObj: any = { + id: "1", + content: "text" + }; + await datastore.datastorePut({ appPath: '/some/path', datastoreName: 'datastore', putItem: itemObj }); sandbox.assert.calledWith( spawnSpy, sinon.match(`datastore put`), @@ -45,7 +49,10 @@ describe('datastore commands', () => { }); describe('query method', () => { it('should invoke `datastore query [expression]`', async () => { - await datastore.datastoreQuery({ appPath: '/some/path', datastoreName: 'datastore', queryExpression: 'id = :id', queryExpressionValues: '{ ":id": "1"}'}); + const expressObj: any = { + id: "1", + }; + await datastore.datastoreQuery({ appPath: '/some/path', datastoreName: 'datastore', queryExpression: 'id = :id', queryExpressionValues: expressObj}); sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore query`)); }); }); diff --git a/packages/cli-test/src/cli/commands/datastore.ts b/packages/cli-test/src/cli/commands/datastore.ts index 8d0d4abde..7660f0e0a 100644 --- a/packages/cli-test/src/cli/commands/datastore.ts +++ b/packages/cli-test/src/cli/commands/datastore.ts @@ -7,11 +7,11 @@ export interface DatastoreCommandArguments { /** @description datastore get primary key value*/ primaryKeyValue: string; /** @description datastore put [item details] */ - putItem: string; + putItem: object; /** @description datastore query [expression] */ queryExpression: string; /** @description datastore query [expression expression_values] */ - queryExpressionValues: string; + queryExpressionValues: object; } /** From 4f92e3d8e229c5bb16706efc751dcdd05c9eea89 Mon Sep 17 00:00:00 2001 From: cchensh Date: Fri, 27 Sep 2024 16:26:13 -0400 Subject: [PATCH 4/7] Update datastore.ts --- packages/cli-test/src/cli/commands/datastore.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli-test/src/cli/commands/datastore.ts b/packages/cli-test/src/cli/commands/datastore.ts index 7660f0e0a..1f4de62c7 100644 --- a/packages/cli-test/src/cli/commands/datastore.ts +++ b/packages/cli-test/src/cli/commands/datastore.ts @@ -21,7 +21,7 @@ export interface DatastoreCommandArguments { export const datastoreGet = async function datastoreGet( args: ProjectCommandArguments & Pick, ): Promise { - const getQueryObj: any = { + const getQueryObj = { datastore: args.datastoreName, id: args.primaryKeyValue }; @@ -40,7 +40,7 @@ export const datastoreGet = async function datastoreGet( export const datastoreDelete = async function datastoreDelete( args: ProjectCommandArguments & Pick, ): Promise { - const deleteQueryObj: any = { + const deleteQueryObj = { datastore: args.datastoreName, id: args.primaryKeyValue }; @@ -59,7 +59,7 @@ export const datastoreDelete = async function datastoreDelete( export const datastorePut = async function datastorePut( args: ProjectCommandArguments & Pick, ): Promise { - const putQueryObj: any = { + const putQueryObj = { datastore: args.datastoreName, item: args.putItem }; @@ -81,7 +81,7 @@ export const datastorePut = async function datastorePut( export const datastoreQuery = async function datastoreQuery( args: ProjectCommandArguments & Pick, ): Promise { - const queryObj: any = { + const queryObj = { datastore: args.datastoreName, expression: args.queryExpression, expression_values: args.queryExpressionValues From e71ce85d10b3d9203bdaf1e8d4d4a6a15c37e693 Mon Sep 17 00:00:00 2001 From: cchensh Date: Fri, 27 Sep 2024 16:39:21 -0400 Subject: [PATCH 5/7] Update datastore.spec.ts --- packages/cli-test/src/cli/commands/datastore.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli-test/src/cli/commands/datastore.spec.ts b/packages/cli-test/src/cli/commands/datastore.spec.ts index 41f0b0720..b750d67a5 100644 --- a/packages/cli-test/src/cli/commands/datastore.spec.ts +++ b/packages/cli-test/src/cli/commands/datastore.spec.ts @@ -25,13 +25,13 @@ describe('datastore commands', () => { describe('get method', () => { it('should invoke `datastore get `', async () => { await datastore.datastoreGet({ appPath: '/some/path', datastoreName: 'datastore', primaryKeyValue: '1' }); - sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore get`)); + sandbox.assert.calledWith(spawnSpy, sinon.match('datastore get')); }); }); describe('delete method', () => { it('should invoke `datastore delete `', async () => { await datastore.datastoreDelete({ appPath: '/some/path', datastoreName: 'datastore', primaryKeyValue: '1' }); - sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore delete`)); + sandbox.assert.calledWith(spawnSpy, sinon.match('datastore delete')); }); }); describe('put method', () => { @@ -43,7 +43,7 @@ describe('datastore commands', () => { await datastore.datastorePut({ appPath: '/some/path', datastoreName: 'datastore', putItem: itemObj }); sandbox.assert.calledWith( spawnSpy, - sinon.match(`datastore put`), + sinon.match('datastore put'), ); }); }); @@ -53,7 +53,7 @@ describe('datastore commands', () => { id: "1", }; await datastore.datastoreQuery({ appPath: '/some/path', datastoreName: 'datastore', queryExpression: 'id = :id', queryExpressionValues: expressObj}); - sandbox.assert.calledWith(spawnSpy, sinon.match(`datastore query`)); + sandbox.assert.calledWith(spawnSpy, sinon.match('datastore query')); }); }); }); From 1c75a6ea915227759dda92b954ad64de39e483eb Mon Sep 17 00:00:00 2001 From: cchensh Date: Fri, 27 Sep 2024 16:39:48 -0400 Subject: [PATCH 6/7] Update datastore.spec.ts --- packages/cli-test/src/cli/commands/datastore.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli-test/src/cli/commands/datastore.spec.ts b/packages/cli-test/src/cli/commands/datastore.spec.ts index b750d67a5..4694a1ea2 100644 --- a/packages/cli-test/src/cli/commands/datastore.spec.ts +++ b/packages/cli-test/src/cli/commands/datastore.spec.ts @@ -36,7 +36,7 @@ describe('datastore commands', () => { }); describe('put method', () => { it('should invoke `datastore put [item details]`', async () => { - const itemObj: any = { + const itemObj = { id: "1", content: "text" }; @@ -49,7 +49,7 @@ describe('datastore commands', () => { }); describe('query method', () => { it('should invoke `datastore query [expression]`', async () => { - const expressObj: any = { + const expressObj = { id: "1", }; await datastore.datastoreQuery({ appPath: '/some/path', datastoreName: 'datastore', queryExpression: 'id = :id', queryExpressionValues: expressObj}); From 256238388d4a59cfc5792ab062beba392fd0efd2 Mon Sep 17 00:00:00 2001 From: cchensh Date: Tue, 1 Oct 2024 11:53:58 -0400 Subject: [PATCH 7/7] Update datastore.ts --- packages/cli-test/src/cli/commands/datastore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-test/src/cli/commands/datastore.ts b/packages/cli-test/src/cli/commands/datastore.ts index 1f4de62c7..9c8716fe1 100644 --- a/packages/cli-test/src/cli/commands/datastore.ts +++ b/packages/cli-test/src/cli/commands/datastore.ts @@ -26,7 +26,7 @@ export const datastoreGet = async function datastoreGet( id: args.primaryKeyValue }; const getQuery = JSON.stringify(getQueryObj); - const cmd = new SlackCLIProcess(`datastore get ${getQuery}`, args); + const cmd = new SlackCLIProcess(`datastore get '${getQuery}'`, args); const proc = await cmd.execAsync({ cwd: args.appPath, });