From 1198cef8ac04298238a68da5ebdd57657ee12f2c Mon Sep 17 00:00:00 2001 From: cchensh Date: Fri, 27 Sep 2024 16:13:22 -0400 Subject: [PATCH] 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, };