Skip to content

Commit

Permalink
Updated with proper way to model the data
Browse files Browse the repository at this point in the history
  • Loading branch information
cchensh committed Sep 27, 2024
1 parent 35c91a7 commit 1198cef
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 38 deletions.
30 changes: 15 additions & 15 deletions packages/cli-test/src/cli/commands/datastore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <query>`', 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 <query>`', 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`));
});
});
});
69 changes: 46 additions & 23 deletions packages/cli-test/src/cli/commands/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,72 @@ import type { ProjectCommandArguments } from '../../types/commands/common_argume
import { SlackCLIProcess } from '../cli-process';

export interface DatastoreCommandArguments {
/** @description datastore get <query> */
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 <query> */
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<DatastoreCommandArguments, 'putDetails'>,
export const datastoreGet = async function datastoreGet(
args: ProjectCommandArguments & Pick<DatastoreCommandArguments, 'datastoreName' | 'primaryKeyValue'>,
): Promise<string> {
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,
});
return proc.output;
};

/**
* `slack datastore get`
* `slack datastore delete`
* @returns command output
*/
export const datastoreGet = async function datastoreGet(
args: ProjectCommandArguments & Pick<DatastoreCommandArguments, 'getQuery'>,
export const datastoreDelete = async function datastoreDelete(
args: ProjectCommandArguments & Pick<DatastoreCommandArguments, 'datastoreName' | 'primaryKeyValue'>,
): Promise<string> {
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,
});
return proc.output;
};

/**
* `slack datastore delete`
* `slack datastore put`
* @returns command output
*/
export const datastoreDelete = async function datastoreDelete(
args: ProjectCommandArguments & Pick<DatastoreCommandArguments, 'deleteQuery'>,
export const datastorePut = async function datastorePut(
args: ProjectCommandArguments & Pick<DatastoreCommandArguments, 'datastoreName' | 'putItem'>,
): Promise<string> {
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,
});
Expand All @@ -62,10 +79,16 @@ export const datastoreDelete = async function datastoreDelete(
* @returns command output
*/
export const datastoreQuery = async function datastoreQuery(
args: ProjectCommandArguments & Pick<DatastoreCommandArguments, 'queryExpression'>,
args: ProjectCommandArguments & Pick<DatastoreCommandArguments, 'datastoreName' | 'queryExpression' | 'queryExpressionValues'>,
): Promise<string> {
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({
Expand All @@ -75,8 +98,8 @@ export const datastoreQuery = async function datastoreQuery(
};

export default {
datastorePut,
datastoreGet,
datastoreDelete,
datastorePut,
datastoreQuery,
};

0 comments on commit 1198cef

Please sign in to comment.