-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli-test(feat): Added datastore
CLI commands
#2041
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
35c91a7
Added datastore basic command
cchensh 1198cef
Updated with proper way to model the data
cchensh b47b70a
updated data type
cchensh 4f92e3d
Update datastore.ts
cchensh e71ce85
Update datastore.spec.ts
cchensh 1c75a6e
Update datastore.spec.ts
cchensh 2562383
Update datastore.ts
cchensh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <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" }'`)); | ||
}); | ||
}); | ||
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" }'`)); | ||
}); | ||
}); | ||
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"} }'`)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import type { ProjectCommandArguments } from '../../types/commands/common_arguments'; | ||
import { SlackCLIProcess } from '../cli-process'; | ||
|
||
export interface DatastoreCommandArguments { | ||
/** @description datastore get <query> */ | ||
getQuery: string; | ||
/** @description datastore put [item details] */ | ||
putDetails: string; | ||
/** @description datastore query [expression] */ | ||
queryExpression: string; | ||
/** @description datastore delete <query> */ | ||
deleteQuery: string; | ||
} | ||
|
||
/** | ||
* `slack datastore put` | ||
* @returns command output | ||
*/ | ||
export const datastorePut = async function datastorePut( | ||
args: ProjectCommandArguments & Pick<DatastoreCommandArguments, 'putDetails'>, | ||
): Promise<string> { | ||
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<DatastoreCommandArguments, 'getQuery'>, | ||
): Promise<string> { | ||
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<DatastoreCommandArguments, 'deleteQuery'>, | ||
): Promise<string> { | ||
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<DatastoreCommandArguments, 'queryExpression'>, | ||
): Promise<string> { | ||
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, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I'm using general string for datastore commands to make it easier than pre-define attributes such as
datastore
,item
, andexpression
, etcThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this will make it easy to make mistakes. I think we should model these just like we model the actual methods:
apps.datastore.get
method needsdatastore
string andid
stringapps.datastore.query
method needsdatastore
string, and its optional arguments, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense, I'd say for
get
method,id
is not a must as it's defined in the manifest as primary key. I'd like to change by adding thedatastore
as the new argument here.Edit: my bad the id is always presented for get and delete command.