Skip to content

Commit 56a1a30

Browse files
Bugfix/353 fe be pipeline incompatibility (#369)
* Fixed REST endpoint to expect pipeline array * Refactored loadPipelinesByDatasourceId to - expect an array - update the corresponding elements inside the state attribute 'pipeline' - added getter for retrieving pipelines by datasourceId from state * Adjusted and enabled pact tests for getPipelinesByDatasourceId * Fixed pact tests for getByDatasourceId: - in case of non found: switch to 200 + empty array - in case of NaN: switch to testing getAll (due to BE impl of getByDatasourceId) * Fixed getter naming * Small pact fixes * Removed unused VUEX getter * Refactored getAll endpoint to return 400 in case of datasourceId is NaN * Fixed pact tests to reflect 400 on datasource is NaN Co-authored-by: Georg Schwarz <[email protected]>
1 parent b1633f8 commit 56a1a30

File tree

5 files changed

+64
-22
lines changed

5 files changed

+64
-22
lines changed

pipeline/src/api/rest/pipelineConfigEndpoint.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,20 @@ export class PipelineConfigEndpoint {
102102
req: express.Request,
103103
res: express.Response,
104104
): Promise<void> => {
105-
const datasourceId = Number.parseInt(
106-
this.getQueryParameter(req, 'datasourceId'),
107-
10,
108-
);
109-
if (Number.isNaN(datasourceId)) {
105+
const datasourceIdParameter = this.getQueryParameter(req, 'datasourceId');
106+
// Check if datasourceId query parameter was given
107+
if (!datasourceIdParameter) {
108+
// No datasourceId parameter given -> return all
110109
const configs = await this.pipelineConfigManager.getAll();
111110
res.status(200).json(configs);
112111
return;
113112
}
113+
// DatasourceId parameter given -> check on NaN
114+
const datasourceId = Number.parseInt(datasourceIdParameter, 10);
115+
if (Number.isNaN(datasourceId)) {
116+
res.status(400).send('Invalid query parameter datasourceId');
117+
return;
118+
}
114119
const configs = await this.pipelineConfigManager.getByDatasourceId(
115120
datasourceId,
116121
);

ui/src/pipeline.consumer.pact.fixtures.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,22 @@ export function getByDatasourceIdRequest(datasourceId: number): RequestOptions {
8080
};
8181
}
8282

83+
export const getByDatasourceIdEmptyResponse: ResponseOptions = {
84+
// TODO any success status code is actually acceptable (i.e. 2xx)
85+
status: 200,
86+
headers: {
87+
'Content-Type': 'application/json; charset=utf-8',
88+
},
89+
body: [],
90+
};
91+
8392
export const getByDatasourceIdSuccessResponse: ResponseOptions = {
8493
// TODO any success status code is actually acceptable (i.e. 2xx)
8594
status: 200,
8695
headers: {
8796
'Content-Type': 'application/json; charset=utf-8',
8897
},
89-
body: like(examplePipeline),
98+
body: eachLike(examplePipeline),
9099
};
91100

92101
export const createRequestTitle = 'a request for creating a pipeline';

ui/src/pipeline.consumer.pact.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
getAllRequest,
2323
getAllRequestTitle,
2424
getAllSuccessResponse,
25+
getByDatasourceIdEmptyResponse,
2526
getByDatasourceIdRequest,
2627
getByDatasourceIdRequestTitle,
2728
getByDatasourceIdSuccessResponse,
@@ -150,9 +151,8 @@ pactWith(options, provider => {
150151
});
151152
});
152153

153-
// TODO do not skip these tests anymore as soon as issue #353 is solved
154-
describe.skip('getting a pipeline by datasource id', () => {
155-
describe('when a pipeline with the requested datasource id exist', () => {
154+
describe('getting pipelines by datasource id', () => {
155+
describe('when a pipeline with the requested datasource id exists', () => {
156156
const id = examplePipeline.datasourceId;
157157

158158
beforeEach(async () => {
@@ -164,10 +164,10 @@ pactWith(options, provider => {
164164
});
165165
});
166166

167-
it('returns the requested pipeline', async () => {
168-
const pipeline = await restService.getPipelineByDatasourceId(id);
167+
it('returns the requested pipelines', async () => {
168+
const pipelines = await restService.getPipelineByDatasourceId(id);
169169

170-
expect(pipeline).toStrictEqual(examplePipeline);
170+
expect(pipelines).toStrictEqual([examplePipeline]);
171171
});
172172
});
173173

@@ -179,14 +179,14 @@ pactWith(options, provider => {
179179
state: `pipelines with datasource id ${id} do not exist`,
180180
uponReceiving: getByDatasourceIdRequestTitle(id),
181181
withRequest: getByDatasourceIdRequest(id),
182-
willRespondWith: notFoundResponse,
182+
willRespondWith: getByDatasourceIdEmptyResponse,
183183
});
184184
});
185185

186-
it('throws an error', async () => {
187-
await expect(
188-
restService.getPipelineByDatasourceId(id),
189-
).rejects.toThrow(Error);
186+
it('returns an empty pipeline array', async () => {
187+
const pipelines = await restService.getPipelineByDatasourceId(id);
188+
189+
expect(pipelines).toStrictEqual([]);
190190
});
191191
});
192192

ui/src/pipeline/pipeline.module.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { PipelineTransRest } from './pipelineTransRest';
66

77
import { PIPELINE_SERVICE_URL } from '@/env';
88

9+
interface PipelinesByDatasourcePayload {
10+
datasourceId: number;
11+
pipelines: Pipeline[];
12+
}
13+
914
@Module({ namespaced: true })
1015
export default class PipelineModule extends VuexModule {
1116
private pipelines: Pipeline[] = [];
@@ -24,6 +29,21 @@ export default class PipelineModule extends VuexModule {
2429
this.isLoadingPipelines = false;
2530
}
2631

32+
@Mutation
33+
setPipelinesByDatasourceId(payload: PipelinesByDatasourcePayload): void {
34+
for (const newPipeline of payload.pipelines) {
35+
const index = this.pipelines.findIndex(el => el.id === newPipeline.id);
36+
if (index >= 0) {
37+
// Already part of array -> replace
38+
this.pipelines[index] = newPipeline;
39+
} else {
40+
// Not found -> insert
41+
this.pipelines.push(newPipeline);
42+
}
43+
}
44+
this.isLoadingPipelines = false;
45+
}
46+
2747
@Mutation
2848
setPipelineStates(value: Map<number, string>): void {
2949
this.pipelineStates = value;
@@ -81,9 +101,17 @@ export default class PipelineModule extends VuexModule {
81101
return await this.restService.getPipelineById(id);
82102
}
83103

84-
@Action({ commit: 'setSelectedPipeline', rawError: true })
85-
async loadPipelineByDatasourceId(datasourceId: number): Promise<Pipeline> {
86-
return await this.restService.getPipelineByDatasourceId(datasourceId);
104+
@Action({ commit: 'setPipelinesByDatasourceId', rawError: true })
105+
async loadPipelinesByDatasourceId(
106+
datasourceId: number,
107+
): Promise<PipelinesByDatasourcePayload> {
108+
const pipelines: Pipeline[] = await this.restService.getPipelineByDatasourceId(
109+
datasourceId,
110+
);
111+
return {
112+
datasourceId: datasourceId,
113+
pipelines: pipelines,
114+
};
87115
}
88116

89117
@Action({ commit: 'setPipelines', rawError: true })

ui/src/pipeline/pipelineRest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export class PipelineRest {
2828
return JSON.parse(response.data) as Pipeline;
2929
}
3030

31-
async getPipelineByDatasourceId(datasourceId: number): Promise<Pipeline> {
31+
async getPipelineByDatasourceId(datasourceId: number): Promise<Pipeline[]> {
3232
const response = await this.httpPipelineConfigs.get(
3333
`?datasourceId=${datasourceId}`,
3434
);
35-
return JSON.parse(response.data) as Pipeline;
35+
return JSON.parse(response.data) as Pipeline[];
3636
}
3737

3838
async createPipeline(pipeline: Pipeline): Promise<Pipeline> {

0 commit comments

Comments
 (0)