Add fake API to allow for testing of requests

This commit is contained in:
Michał Gdula 2024-04-27 19:23:06 +01:00
parent 2686fb904c
commit 782c88d082
7 changed files with 86 additions and 46 deletions

View file

@ -1,4 +1,4 @@
import Items from '%/lib/testData.js';
import Items from '%/lib/test-data.js';
export async function getPopularToday() {
const res = await fetch("/api/items")

30
front/src/lib/test-api.js Normal file
View file

@ -0,0 +1,30 @@
import Items from '%/lib/test-data.js';
async function fakeDelay(timeout = 1000) {
await new Promise(resolve => setTimeout(resolve, timeout));
}
export async function getPopularToday() {
const data = Items;
await fakeDelay(2000)
return data;
}
export async function getMenuItems() {
const data = [
{
name: "Main Menu",
items: Items,
},
{
name: "Breakfast",
items: [],
},
{
name: "Seasonal",
items: Items,
},
];
await fakeDelay(2000)
return data;
}

View file

@ -1,53 +1,72 @@
// "vegan", "fish", "nut", "spicy", "gluten"
let Items;
export default Items = [
const Items = [
// soap: {
{
uuid: "soap",
name: "Bar of Soap",
price: 69.99,
labels: ["vegan", "spicy"],
},
// sock: {
{
uuid: "sock",
name: "Sock",
price: 21,
labels: ["vegan", "fish", "nut", "spicy"],
},
// brick: {
{
uuid: "brick",
name: "Brick",
price: 0,
labels: ["spicy"],
},
// toast: {
{
uuid: "toast",
name: "Toast",
price: 4382749832743,
labels: ["gluten"],
},
// water: {
{
uuid: "water",
name: "water",
price: 1,
labels: ["fish"],
},
// mouldy_bread: {
{
uuid: "mouldy_bread",
name: "half eaten mouldy bread",
price: -99,
labels: ["nut"],
},
// gwagwa: {
{
uuid: "gwagwa",
name: "GwaGwa",
price: "Priceless",
labels: ["nut"],
image: "/dab.jpg",
},
// hogmelon: {
{
uuid: "hogmelon",
name: "Hogermellon",
price: "1111",
labels: ["fish"],
image: "/wathog.jpg",
},
// bluhog: {
{
uuid: "bluhog",
name: "Blue HOGGGGG",
price: "ARUGH",
labels: ["nut", "gluten", "spicy"],
image: "/sonichog.jpg",
},
];
export default Items;