-
Notifications
You must be signed in to change notification settings - Fork 236
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
766 store circuit inputs translation schema #783
Merged
biscuitdey
merged 18 commits into
main
from
766-store-circuit-inputs-translation-schema
Jun 25, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8def4ff
Tell vscode to use workspace typescript version
ognjenkurtic 7386e11
Add circuitInputsTranslationSchema field to workstep + migration
ognjenkurtic ffaa8f9
Add extremely basic validateCircuitInputTranslationSchema method to c…
ognjenkurtic 6699c25
Implement first version of AddCircuitInputsSchemaCommand with a handler
ognjenkurtic 52dcf72
Implement endpoint for setting circuit input schema on a workstep; ad…
ognjenkurtic cfb5f85
Run prettier
ognjenkurtic b577957
Extend validateCircuitInputTranslationSchema method and add first bat…
ognjenkurtic a0c5287
Add dummy circuit input schema creation step to e2e test
ognjenkurtic 0d90443
validateCircuitInputTranslationSchema - Parse validation reuslt and t…
ognjenkurtic 999feda
Rename output param for validateCircuitInputTranslationSchema for bet…
ognjenkurtic fc2b672
Rename setCircuitInputsSchema command to updateCircuitInputsSchema
ognjenkurtic f869d30
Add circuitInputsTranslationSchema as JSON column to workstep
ognjenkurtic 410ab21
Update postman collection with example schema
ognjenkurtic 6c30aa3
Finish rename of SetCircuitInputSchema to UpdateCircuitInputSchema
ognjenkurtic 05ee92f
Cleanup from local testing
ognjenkurtic af581fc
Fix validateCircuitInputTranslationSchema return type to be a single …
ognjenkurtic 3c9230d
Fix failing unit tests related to circuit input parsers
ognjenkurtic 0dc2cf3
Fix assert for invalid JSON schema test in ciruit parser service
ognjenkurtic 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,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
2 changes: 2 additions & 0 deletions
2
...ma/migrations/20240411211906_add_circuitinputstranslationschema_to_workstep/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Workstep" ADD COLUMN "circuitInputsTranslationSchema" JSONB; |
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
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
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
40 changes: 40 additions & 0 deletions
40
.../bri-3/src/bri/workgroup/worksteps/api/dtos/request/updateCircuitInputsSchema.dto.spec.ts
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,40 @@ | ||
import { plainToInstance } from 'class-transformer'; | ||
import { validate } from 'class-validator'; | ||
import { SHOULD_NOT_BE_EMPTY_VALIDATION_MESSAGE } from '../../../../../shared/constants'; | ||
import { UpdateCircuitInputsSchemaDto } from './updateCircuitInputsSchema.dto'; | ||
|
||
describe('UpdateCircuitInputsSchemaDto', () => { | ||
it('should return error in case schema not provided.', async () => { | ||
// Arrange | ||
const dto = { wrong: '1' }; | ||
const setCircuitInputsSchemaDto = plainToInstance( | ||
UpdateCircuitInputsSchemaDto, | ||
dto, | ||
); | ||
|
||
// Act | ||
const errors = await validate(setCircuitInputsSchemaDto); | ||
|
||
// Assert | ||
expect(errors.length).toBe(1); | ||
expect(errors[0].property).toEqual('schema'); | ||
expect(errors[0].constraints?.isNotEmpty).toContain( | ||
'schema ' + SHOULD_NOT_BE_EMPTY_VALIDATION_MESSAGE, | ||
); | ||
}); | ||
|
||
it('should return no error if all required properties provided.', async () => { | ||
// Arrange | ||
const dto = { schema: 'test' }; | ||
const setCircuitInputsSchemaDto = plainToInstance( | ||
UpdateCircuitInputsSchemaDto, | ||
dto, | ||
); | ||
|
||
// Act | ||
const errors = await validate(setCircuitInputsSchemaDto); | ||
|
||
// Assert | ||
expect(errors.length).toBe(0); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
examples/bri-3/src/bri/workgroup/worksteps/api/dtos/request/updateCircuitInputsSchema.dto.ts
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,6 @@ | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
export class UpdateCircuitInputsSchemaDto { | ||
@IsNotEmpty() | ||
schema: string; | ||
} |
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
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
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
39 changes: 39 additions & 0 deletions
39
...steps/capabilities/updateCircuitInputsSchema/updateCircuitInputsSchema.command.handler.ts
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,39 @@ | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { WorkstepAgent } from '../../agents/worksteps.agent'; | ||
import { WorkstepStorageAgent } from '../../agents/workstepsStorage.agent'; | ||
import { UpdateCircuitInputsSchemaCommand } from './updateCircuitInputsSchema.command'; | ||
import { InjectMapper } from '@automapper/nestjs'; | ||
import { Mapper } from '@automapper/core'; | ||
import { Workstep } from '../../models/workstep'; | ||
import { WorkstepDto } from '../../api/dtos/response/workstep.dto'; | ||
|
||
@CommandHandler(UpdateCircuitInputsSchemaCommand) | ||
export class UpdateCircuitInputsSchemaCommandHandler | ||
implements ICommandHandler<UpdateCircuitInputsSchemaCommand> | ||
{ | ||
constructor( | ||
@InjectMapper() private readonly mapper: Mapper, | ||
private agent: WorkstepAgent, | ||
private storageAgent: WorkstepStorageAgent, | ||
) {} | ||
|
||
async execute(command: UpdateCircuitInputsSchemaCommand) { | ||
const workstepToUpdate = | ||
await this.agent.fetchUpdateCandidateAndThrowIfUpdateValidationFails( | ||
command.workstepId, | ||
); | ||
|
||
this.agent.throwIfCircuitInputTranslationSchemaInvalid(command.schema); | ||
|
||
this.agent.updateCircuitInputTranslationSchema( | ||
workstepToUpdate, | ||
command.schema, | ||
); | ||
|
||
const updatedWorkstep = await this.storageAgent.updateWorkstep( | ||
workstepToUpdate, | ||
); | ||
|
||
return this.mapper.map(updatedWorkstep, Workstep, WorkstepDto); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...oup/worksteps/capabilities/updateCircuitInputsSchema/updateCircuitInputsSchema.command.ts
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,6 @@ | ||
export class UpdateCircuitInputsSchemaCommand { | ||
constructor( | ||
public readonly workstepId: string, | ||
public readonly schema: string, | ||
) {} | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
can error occur here?
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.
Not really, asigning string value