Add aggregate results by entityRef
Signed-off-by: Roohn <tol.ronald@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
EntityRatingsData,
|
||||
FeedbackResponse,
|
||||
Rating,
|
||||
Ratings,
|
||||
} from '@backstage/plugin-entity-feedback-common';
|
||||
|
||||
/**
|
||||
@@ -40,6 +41,11 @@ export interface EntityFeedbackApi {
|
||||
|
||||
getRatings(entityRef: string): Promise<Omit<Rating, 'entityRef'>[]>;
|
||||
|
||||
/**
|
||||
* Returns anonymized aggregated results for one entityRef
|
||||
*/
|
||||
getRatingAggregates(entityRef: string): Promise<Ratings>;
|
||||
|
||||
recordResponse(
|
||||
entityRef: string,
|
||||
response: Omit<FeedbackResponse, 'entityRef' | 'userRef'>,
|
||||
|
||||
@@ -121,6 +121,24 @@ describe('EntityFeedbackClient', () => {
|
||||
expect(response).toEqual(ratings);
|
||||
});
|
||||
|
||||
it('getRatingAggregates', async () => {
|
||||
const ratings = { LIKE: 3, DISLIKE: 5 };
|
||||
|
||||
server.use(
|
||||
rest.get(
|
||||
`${mockBaseUrl}/ratings/${encodeURIComponent(
|
||||
'component:default/service',
|
||||
)}/aggregate`,
|
||||
(_, res, ctx) => res(ctx.json(ratings)),
|
||||
),
|
||||
);
|
||||
|
||||
const response = await client.getRatingAggregates(
|
||||
'component:default/service',
|
||||
);
|
||||
expect(response).toEqual(ratings);
|
||||
});
|
||||
|
||||
it('recordResponse', async () => {
|
||||
expect.assertions(1);
|
||||
const response = {
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
EntityRatingsData,
|
||||
FeedbackResponse,
|
||||
Rating,
|
||||
Ratings,
|
||||
} from '@backstage/plugin-entity-feedback-common';
|
||||
|
||||
import { EntityFeedbackApi } from './EntityFeedbackApi';
|
||||
@@ -97,6 +98,22 @@ export class EntityFeedbackClient implements EntityFeedbackApi {
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async getRatingAggregates(entityRef: string): Promise<Ratings> {
|
||||
const baseUrl = await this.discoveryApi.getBaseUrl('entity-feedback');
|
||||
const resp = await this.fetchApi.fetch(
|
||||
`${baseUrl}/ratings/${encodeURIComponent(entityRef)}/aggregate`,
|
||||
{
|
||||
method: 'GET',
|
||||
},
|
||||
);
|
||||
|
||||
if (!resp.ok) {
|
||||
throw await ResponseError.fromResponse(resp);
|
||||
}
|
||||
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async recordResponse(
|
||||
entityRef: string,
|
||||
response: Omit<FeedbackResponse, 'entityRef' | 'userRef'>,
|
||||
|
||||
Reference in New Issue
Block a user