Skip to content

Commit

Permalink
fix: changes by review
Browse files Browse the repository at this point in the history
  • Loading branch information
louisewang1 committed Mar 16, 2022
1 parent 4406cb3 commit c0bfa0f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/api/itemValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getItemValidationStatuses = async ({ API_HOST }: QueryClientConfig)
export const getItemValidationReviewStatuses = async ({ API_HOST }: QueryClientConfig) =>
axios.get(`${API_HOST}/${GET_ITEM_VALIDATION_REVIEW_STATUSES_ROUTE}`).then(({ data }) => data);

export const getValidationStatus = async (
export const getItemValidationAndReviews = async (
{ API_HOST }: QueryClientConfig,
itemId: UUID,
) =>
Expand Down
4 changes: 2 additions & 2 deletions src/config/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ export const MUTATION_KEYS = {
DELETE_ITEM_LIKE: 'deleteItemLike',
ADD_FAVORITE_ITEM: 'addFavoriteItem',
DELETE_FAVORITE_ITEM: 'deleteFavoriteItem',
POST_VALIDATION: 'postItemValidation',
UPDATE_VALIDATION_REVIEW: 'updateItemValidationReview',
POST_ITEM_VALIDATION: 'postItemValidation',
UPDATE_ITEM_VALIDATION_REVIEW: 'updateItemValidationReview',
};
2 changes: 1 addition & 1 deletion src/hooks/itemValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default (queryConfig: QueryClientConfig) => {
useQuery({
queryKey: buildItemValidationAndReviewsKey(itemId),
queryFn: () =>
Api.getValidationStatus(queryConfig, itemId).then((data) => List(data)),
Api.getItemValidationAndReviews(queryConfig, itemId).then((data) => List(data)),
...defaultOptions,
enabled: Boolean(itemId),
});
Expand Down
16 changes: 8 additions & 8 deletions src/mutations/itemValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ describe('Item Validation Mutations', () => {
nock.cleanAll();
});

describe(MUTATION_KEYS.POST_VALIDATION, () => {
describe(MUTATION_KEYS.POST_ITEM_VALIDATION, () => {
const itemId = 'item-id';
const route = `/${buildPostItemValidationRoute(itemId)}`;
const mutation = () => useMutation(MUTATION_KEYS.POST_VALIDATION);
const mutation = () => useMutation(MUTATION_KEYS.POST_ITEM_VALIDATION);
const key = buildItemValidationAndReviewsKey(itemId);

it('Post validation', async () => {
it('Post item validation', async () => {
queryClient.setQueryData(key, List([ITEM_VALIDATION_STATUS]));

const endpoints = [
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Item Validation Mutations', () => {
type: postItemValidationRoutine.SUCCESS,
});
});
it('Unauthorized to post item category', async () => {
it('Unauthorized to post item validation', async () => {
queryClient.setQueryData(key, List([ITEM_VALIDATION_STATUS]));
const endpoints = [
{
Expand Down Expand Up @@ -95,17 +95,17 @@ describe('Item Validation Mutations', () => {
});
});

describe(MUTATION_KEYS.UPDATE_VALIDATION_REVIEW, () => {
describe(MUTATION_KEYS.UPDATE_ITEM_VALIDATION_REVIEW, () => {
const id = 'id1';
const itemId = 'item-id';
const status = 'accepted';
const reason = '';
const route = `/${buildUpdateItemValidationReviewRoute(id)}`;
const mutation = () => useMutation(MUTATION_KEYS.UPDATE_VALIDATION_REVIEW);
const mutation = () => useMutation(MUTATION_KEYS.UPDATE_ITEM_VALIDATION_REVIEW);
const statusKey = buildItemValidationAndReviewsKey(itemId);
const reviewsKey = ITEM_VALIDATION_REVIEWS_KEY;

it('Update validation review record', async () => {
it('Update item validation review record', async () => {
queryClient.setQueryData(statusKey, ITEM_VALIDATION_STATUS);
queryClient.setQueryData(reviewsKey, FULL_VALIDATION_RECORDS);

Expand Down Expand Up @@ -143,7 +143,7 @@ describe('Item Validation Mutations', () => {
);
});

it('Unauthorized to update validation review', async () => {
it('Unauthorized to update item validation review', async () => {
queryClient.setQueryData(statusKey, ITEM_VALIDATION_STATUS);
queryClient.setQueryData(reviewsKey, FULL_VALIDATION_RECORDS);

Expand Down
4 changes: 2 additions & 2 deletions src/mutations/itemValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default (queryClient: QueryClient, queryConfig: QueryClientConfig) => {
const { notifier } = queryConfig;

// payload: itemId
queryClient.setMutationDefaults(MUTATION_KEYS.POST_VALIDATION, {
queryClient.setMutationDefaults(MUTATION_KEYS.POST_ITEM_VALIDATION, {
mutationFn: (payload) =>
Api.postItemValidation(payload, queryConfig).then(() => payload),
onSuccess: () => {
Expand All @@ -35,7 +35,7 @@ export default (queryClient: QueryClient, queryConfig: QueryClientConfig) => {
});

// payload: id (entry id), itemId, status, reason
queryClient.setMutationDefaults(MUTATION_KEYS.UPDATE_VALIDATION_REVIEW, {
queryClient.setMutationDefaults(MUTATION_KEYS.UPDATE_ITEM_VALIDATION_REVIEW, {
mutationFn: (payload) =>
Api.updateItemValidationReview(payload, queryConfig),
onSuccess: () => {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export type GraaspError = {
data?: unknown;
};

// a combined record from item-validation, item-validation-review, item-validation-process
export type FullValidationRecord = {
id: string;
itemId: string;
Expand Down

0 comments on commit c0bfa0f

Please sign in to comment.