import { RequestOptions , ResponseOptions } from '@pact-foundation/pact' ; import { eachLike , like } from '@pact-foundation/pact/src/dsl/matchers' ; import { JobResult , TransformationRequest , } from './pipeline/edit/transformation/transformation' ; import Pipeline , { HealthStatus } from './pipeline/pipeline' ; export const examplePipelineId = 1 ; export const exampleDatasourceId = 2 ; export const examplePipelineWithoutSchema = { id : examplePipelineId , datasourceId : exampleDatasourceId , metadata : { author : 'some author' , description : 'some description' , displayName : 'some display name' , license : 'some license' , } , transformation : { func : 'some function' , } , } ; export const examplePipelineWithSchema = { ... examplePipelineWithoutSchema , schema : { } , } ; export const getAllRequestTitle = 'a request for getting all pipelines' ; export const getAllRequest = { method : 'GET' , path : '/configs/' , } ; export const getAllEmptyResponse = { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : [ ] , } ; export function getAllSuccessResponse ( withSchema ) { return { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : eachLike ( withSchema ? examplePipelineWithSchema : examplePipelineWithoutSchema ) , } ; } export function getByIdRequestTitle ( id ) { return `a request for getting the pipeline with id ${ id }` ; } export function getByIdRequest ( id ) { return { method : 'GET' , path : `/configs/${ id }` , } ; } export function getByIdSuccessResponse ( withSchema ) { return { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : like ( withSchema ? examplePipelineWithSchema : examplePipelineWithoutSchema ) , } ; } export function getByDatasourceIdRequestTitle ( datasourceId ) { return `a request for getting pipelines with datasource id ${ datasourceId }` ; } export function getByDatasourceIdRequest ( datasourceId ) { return { method : 'GET' , path : '/configs/' , query : `datasourceId=${ datasourceId }` , } ; } export const getByDatasourceIdEmptyResponse = { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : [ ] , } ; export function getByDatasourceIdSuccessResponse ( withSchema ) { return { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : eachLike ( withSchema ? examplePipelineWithSchema : examplePipelineWithoutSchema ) , } ; } export function createRequestTitle ( withSchema ) { return `a request for creating a pipeline ${ withSchema ? 'with' : 'without' } schema` ; } export function createRequest ( pipeline ) { return { method : 'POST' , path : '/configs/' , headers : { 'Content-Type' : 'application/json' , } , body : pipeline , } ; } export function createSuccessResponse ( pipeline ) { return { status : 201 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : like ( pipeline ) , } ; } export function updateRequestTitle ( id , withSchema ) { return `a request for updating the pipeline with id ${ id } ${ withSchema ? 'including' : 'excluding' } its schema` ; } export function updateRequest ( pipeline ) { return { method : 'PUT' , path : `/configs/${ pipeline . id }` , headers : { 'Content-Type' : 'application/json' , } , body : pipeline , } ; } export function updateSuccessResponse ( withSchema ) { return { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : like ( withSchema ? examplePipelineWithSchema : examplePipelineWithoutSchema ) , } ; } export function deleteRequestTitle ( id ) { return `a request for deleting the pipeline with id ${ id }` ; } export function deleteRequest ( id ) { return { method : 'DELETE' , path : `/configs/${ id }` , } ; } export function deleteSuccessResponse ( withSchema ) { return { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : like ( withSchema ? examplePipelineWithSchema : examplePipelineWithoutSchema ) , } ; } export const exampleTransformedDataId = 1 ; export function getLatestTransformedDataRequestTitle ( id ) { return `a request for getting latest transformed data with id ${ id }` ; } export function getLatestTransformedDataRequest ( id ) { return { method : 'GET' , path : `/transdata/${ id }/transforms/latest` , } ; } export function getLatestTransformedDataSuccessResponse ( healthStatus ) { return { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : { id : like ( exampleTransformedDataId ) , healthStatus : healthStatus , } , } ; } export const exampleValidTransformationRequest = { func : 'data.value = 42; return data;' , data : { } , } ; export const exampleSuccessJobResult = { data : { } , stats : { durationInMilliSeconds : 3.14 , startTimestamp : 123 , endTimestamp : 456 , } , } ; export const exampleTransformationRequestWithInvalidSyntax = { func : 'n0t v4l1d j4v4$(r1pt' , data : { } , } ; export const exampleInvalidSyntaxJobResult = { error : { name : 'some error' , message : 'some message' , lineNumber : 1 , position : 2 , stacktrace : [ ] , } , stats : { durationInMilliSeconds : 3.14 , startTimestamp : 123 , endTimestamp : 456 , } , } ; export const exampleTransformationRequestWithErrorThrowingFunction = { func : 'throw new Error()' , data : { } , } ; export const exampleErrorThrownJobResult = { error : { name : 'some error' , message : 'some message' , lineNumber : 1 , position : 2 , stacktrace : [ 'some stacktrace entry' ] , } , stats : { durationInMilliSeconds : 3.14 , startTimestamp : 123 , endTimestamp : 456 , } , } ; export function transformDataRequest ( body ) { return { method : 'POST' , path : '/job' , headers : { 'Content-Type' : 'application/json' , } , body , } ; } export const transformDataSuccessResponse = { status : 200 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : like ( exampleSuccessJobResult ) , } ; export const transformDataInvalidSyntaxResponse = { status : 400 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : { error : { name : like ( exampleInvalidSyntaxJobResult . error ?. name ) , message : like ( exampleInvalidSyntaxJobResult . error ?. message ) , lineNumber : like ( exampleInvalidSyntaxJobResult . error ?. lineNumber ) , position : like ( exampleInvalidSyntaxJobResult . error ?. position ) , stacktrace : exampleInvalidSyntaxJobResult . error ?. stacktrace , } , stats : like ( exampleInvalidSyntaxJobResult . stats ) , } , } ; export const transformDataErrorThrownResponse = { status : 400 , headers : { 'Content-Type' : 'application/json; charset=utf-8' , } , body : like ( { ... exampleErrorThrownJobResult , error : { ... exampleErrorThrownJobResult . error , stacktrace : eachLike ( exampleErrorThrownJobResult . error ?. stacktrace [ 0 ] ) , } , } ) , } ; export const notFoundResponse = { status : 404 , } ; export const badRequestResponse = { status : 400 , } ;