Closed slackermorris closed 7 months ago
So, the error very much resides with the schema
and not other things in the fullSchema
. Definitely within the body. So, how can I test the schema in its limited scope?
So, just using the eventSchema
worked when parsing.
export const eventSchema = z.object({
body: z.object({
username: movieSchema.shape.username,
payload: movieSchema.shape.movieDetails,
}),
pathParameters: z.object({
watchlistId: movieSchema.shape.watchlistId,
}),
});
const exampleEvent = {
body: {
username: "trial-user",
payload: {
title: "The Matrix",
year: "1999",
genre: "Action",
director: "The Wachowskis",
actors: [
"Keanu Reeves",
"Laurence Fishburne",
"Carrie-Anne Moss",
],
plot: "A computer hacker learns about the true nature of his reality and his role in the war against its controllers.",
poster:
"https://m.media-amazon.com/images/I/71c5x9zK0NL._AC_SY679_.jpg",
imdbRating: "8.7",
poster_path: "/hEpWvX6Bp79eLxY1kX5ZZJcme5U.jpg",
release_date: "1999-03-30",
overview: "unsure",
cast: [
{
name: "Keanu Reeves",
character: "Neo",
},
{
name: "Laurence Fishburne",
character: "Morpheus",
},
{
name: "Carrie-Anne Moss",
character: "Trinity",
},
],
genres: [
{
name: "Action",
},
{
name: "Science Fiction",
},
],
},
},
pathParameters: {
watchlistId: "qfJTV11_V5KERNH7V0qT3",
},
};
console.log("beginning parsing example event");
console.log(testThisSchema.parse(exampleEvent));
console.log("finished parsing request event");
testThisSchema
being eventSchema
I think that I solved it. The issue was that genre
on the body
did not match the expected type definition.
type Genre = {
id: number;
name: string;
};
genres: Array<Pick<Genre, "name">>
Does not mean that genres
is going to be an array of strings. It instead means it will be an array like:
genres: [ { name: 'genreName' } ]
To achieve the mapping I was after I need to do something like:
genres: Array<Genre['name']>
Now, why isn't the watchlist loading? Probably the wrong endpoint.
OK I think we are closer to where we want to be. I just need to refactor the getImage
endpoint.
Well, damn. I feel like my work here is done.
This is the request being attempted: