Skip to content

Commit

Permalink
fix/AI rejected generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dereje1 committed Sep 23, 2023
1 parent 448a20b commit 7c6b602
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/src/components/mypins/pincreatemodal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ class PinCreate extends Component<PinCreateProps, PinCreateState> {
description: title.trim(),
AIimageStatus: {
_id,
generatedImage: true,
generatedImage: Boolean(_id),
generatingImage: false,
},
}, updateGeneratedImages);
}, () => (_id ? updateGeneratedImages() : null));
};

handleImageTypes = () => {
Expand Down
3 changes: 2 additions & 1 deletion server/controllers/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const generateAIimage = async (req: Request, res: genericResponseType) =>
const [titleObject] = titleResponse.choices;
res.json({ imgURL: linkObject.url, title: titleObject.text?.trim().replace(/[".]/g, ''), _id });
} catch (error) {
res.json(error);
debug(`Error Generating AI image and title for -> UserId -> ${userId} and description: ${description}, Error: ${error}`);
res.json({ imgURL: '', title: '', _id: null });
}
};
6 changes: 5 additions & 1 deletion tests/server/controllers/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ describe('generating an AI image', () => {
},
};
await generateAIimage(req as genericRequest, res as unknown as Response);
expect(res.json).toHaveBeenCalledWith(Error('Mocked rejection'));
expect(res.json).toHaveBeenCalledWith({
imgURL: '',
title: '',
_id: null,
});
});
});

0 comments on commit 7c6b602

Please sign in to comment.