From 6479cee8937be74d704c82c843aa2c72ea9d4479 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Tue, 17 Mar 2026 22:56:00 +0100 Subject: [PATCH 1/6] implemented fetch and checked for errors --- task-1/cocktail.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/task-1/cocktail.js b/task-1/cocktail.js index 6fd5a62..d4d6906 100644 --- a/task-1/cocktail.js +++ b/task-1/cocktail.js @@ -1,6 +1,8 @@ // API documentation: https://www.thecocktaildb.com/api.php +import { error } from 'console'; import path from 'path'; +import fs from `fs/promises` const BASE_URL = 'https://www.thecocktaildb.com/api/json/v1/1'; @@ -20,6 +22,17 @@ export async function main() { try { // 1. Fetch data from the API at the given URL + const response = await fetch(`https://www.thecocktaildb.com/api/json/v1/1`); + if(!response.ok){ + const error = new error("Error with API"); + throw error; + } + const data = await response.json(); + + + if (!data.drinks || data.drinks.length === 0) { + throw new Error(`No cocktails found for "${cocktailName}"`); + } // 2. Generate markdown content to match the examples // 3. Write the generated content to a markdown file as given by outPath } catch (error) { From 608f0bba92cad0f4421125e64a63a41b515db9a2 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Tue, 17 Mar 2026 23:52:48 +0100 Subject: [PATCH 2/6] passes all tests --- task-1/cocktail.js | 77 +++++++++++++++++++++++++--- task-1/output/margarita.md | 23 +++++++++ task-1/output/nonexistentcocktail.md | 3 ++ 3 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 task-1/output/margarita.md create mode 100644 task-1/output/nonexistentcocktail.md diff --git a/task-1/cocktail.js b/task-1/cocktail.js index d4d6906..4aa8400 100644 --- a/task-1/cocktail.js +++ b/task-1/cocktail.js @@ -2,7 +2,7 @@ import { error } from 'console'; import path from 'path'; -import fs from `fs/promises` +import { writeFile } from 'fs/promises'; const BASE_URL = 'https://www.thecocktaildb.com/api/json/v1/1'; @@ -27,18 +27,79 @@ export async function main() { const error = new error("Error with API"); throw error; } - const data = await response.json(); + +const data = await response.json(); + - - if (!data.drinks || data.drinks.length === 0) { - throw new Error(`No cocktails found for "${cocktailName}"`); - } // 2. Generate markdown content to match the examples - // 3. Write the generated content to a markdown file as given by outPath + +let markdown = `# Cocktail Recipes\n\n`; + +if (!data.drinks || data.drinks.length === 0) { + throw new Error("No cocktails found with that name."); + +} else { + for (const drink of data.drinks) { + markdown += `## ${drink.strDrink}\n\n`; + + // Use strDrinkThumb medium + if (drink.strDrinkThumb) { + const thumbUrl = `${drink.strDrinkThumb}/medium`; + markdown += `![${drink.strDrink}](${thumbUrl})\n\n`; +} + + // Category & Alcoholic + markdown += `**Category**: ${drink.strCategory || 'Unknown'}\n`; + + let alcoholicText = '—'; + if (drink.strAlcoholic === 'Alcoholic') { + alcoholicText = 'Yes'; + } else if (drink.strAlcoholic === 'Non alcoholic' || drink.strAlcoholic === 'Non-Alcoholic') { + alcoholicText = 'No'; + } + markdown += `**Alcoholic**: ${alcoholicText}\n\n`; + + // Ingredients + markdown += `### Ingredients\n\n`; + let ingredientCount = 0; + + for (let i = 1; i <= 15; i++) { + const ingredient = drink[`strIngredient${i}`]; + if (ingredient && ingredient.trim()) { + ingredientCount++; + const measure = drink[`strMeasure${i}`]?.trim() || ''; + const line = measure ? `${measure} ${ingredient}` : ingredient; + markdown += `- ${line}\n`; + } + } + + if (ingredientCount === 0) { + markdown += `- No ingredients listed\n`; + } + markdown += `\n`; + + // Instructions + markdown += `### Instructions\n${drink.strInstructions || 'No instructions provided.'}\n\n`; + + // Glass + markdown += `Serve in: ${drink.strGlass || 'Unknown'}\n\n`; + + markdown += `---\n\n`; + } +} + + + +// 3. Write the generated content to a markdown file as given by outPath +await writeFile(outPath, markdown, 'utf-8'); +console.log(`Successfully wrote to ${outPath}`); + } catch (error) { // 4. Handle errors - } + console.error(error.message); } + } + // Do not change the code below if (!process.env.VITEST) { diff --git a/task-1/output/margarita.md b/task-1/output/margarita.md new file mode 100644 index 0000000..16e2877 --- /dev/null +++ b/task-1/output/margarita.md @@ -0,0 +1,23 @@ +# Cocktail Recipes + +## Margarita + +![Margarita](https://www.thecocktaildb.com/images/media/drink/5noda61589575158.jpg/medium) + +**Category**: Ordinary Drink +**Alcoholic**: Yes + +### Ingredients + +- 1 1/2 oz Tequila +- 1/2 oz Triple sec +- 1 oz Lime juice +- Salt + +### Instructions +Rub the rim of the glass. + +Serve in: Cocktail glass + +--- + diff --git a/task-1/output/nonexistentcocktail.md b/task-1/output/nonexistentcocktail.md new file mode 100644 index 0000000..03012cc --- /dev/null +++ b/task-1/output/nonexistentcocktail.md @@ -0,0 +1,3 @@ +# Cocktail Recipes + +No cocktails found for "nonexistentcocktail". From 767fa1e2810d01fdd71b6ae89190ebbcc448130e Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Mar 2026 08:01:37 +0100 Subject: [PATCH 3/6] repaired the fetch url --- task-1/cocktail.js | 141 ++++++++++++++++++------------------- task-1/output/margarita.md | 111 ++++++++++++++++++++++++++++- 2 files changed, 178 insertions(+), 74 deletions(-) diff --git a/task-1/cocktail.js b/task-1/cocktail.js index 4aa8400..1da75b6 100644 --- a/task-1/cocktail.js +++ b/task-1/cocktail.js @@ -1,16 +1,16 @@ // API documentation: https://www.thecocktaildb.com/api.php -import { error } from 'console'; -import path from 'path'; -import { writeFile } from 'fs/promises'; +import { error } from "console"; +import path from "path"; +import { writeFile } from "fs/promises"; -const BASE_URL = 'https://www.thecocktaildb.com/api/json/v1/1'; +const BASE_URL = "https://www.thecocktaildb.com/api/json/v1/1"; // Add helper functions as needed here export async function main() { if (process.argv.length < 3) { - console.error('Please provide a cocktail name as a command line argument.'); + console.error("Please provide a cocktail name as a command line argument."); return; } @@ -22,84 +22,79 @@ export async function main() { try { // 1. Fetch data from the API at the given URL - const response = await fetch(`https://www.thecocktaildb.com/api/json/v1/1`); - if(!response.ok){ - const error = new error("Error with API"); - throw error; - } - -const data = await response.json(); + const response = await fetch( + `https://www.thecocktaildb.com/api/json/v1/1/search.php?s=${cocktailName}`, + ); + const data = await response.json(); // 2. Generate markdown content to match the examples -let markdown = `# Cocktail Recipes\n\n`; - -if (!data.drinks || data.drinks.length === 0) { - throw new Error("No cocktails found with that name."); - -} else { - for (const drink of data.drinks) { - markdown += `## ${drink.strDrink}\n\n`; - - // Use strDrinkThumb medium - if (drink.strDrinkThumb) { - const thumbUrl = `${drink.strDrinkThumb}/medium`; - markdown += `![${drink.strDrink}](${thumbUrl})\n\n`; -} - - // Category & Alcoholic - markdown += `**Category**: ${drink.strCategory || 'Unknown'}\n`; - - let alcoholicText = '—'; - if (drink.strAlcoholic === 'Alcoholic') { - alcoholicText = 'Yes'; - } else if (drink.strAlcoholic === 'Non alcoholic' || drink.strAlcoholic === 'Non-Alcoholic') { - alcoholicText = 'No'; - } - markdown += `**Alcoholic**: ${alcoholicText}\n\n`; - - // Ingredients - markdown += `### Ingredients\n\n`; - let ingredientCount = 0; - - for (let i = 1; i <= 15; i++) { - const ingredient = drink[`strIngredient${i}`]; - if (ingredient && ingredient.trim()) { - ingredientCount++; - const measure = drink[`strMeasure${i}`]?.trim() || ''; - const line = measure ? `${measure} ${ingredient}` : ingredient; - markdown += `- ${line}\n`; + let markdown = `# Cocktail Recipes\n\n`; + + if (!data.drinks || data.drinks.length === 0) { + throw new Error("No cocktails found with that name."); + } else { + for (const drink of data.drinks) { + markdown += `## ${drink.strDrink}\n\n`; + + // Use strDrinkThumb medium + if (drink.strDrinkThumb) { + const thumbUrl = `${drink.strDrinkThumb}/medium`; + markdown += `![${drink.strDrink}](${thumbUrl})\n\n`; + } + + // Category & Alcoholic + markdown += `**Category**: ${drink.strCategory || "Unknown"}\n`; + + let alcoholicText = "—"; + if (drink.strAlcoholic === "Alcoholic") { + alcoholicText = "Yes"; + } else if ( + drink.strAlcoholic === "Non alcoholic" || + drink.strAlcoholic === "Non-Alcoholic" + ) { + alcoholicText = "No"; + } + markdown += `**Alcoholic**: ${alcoholicText}\n\n`; + + // Ingredients + markdown += `### Ingredients\n\n`; + let ingredientCount = 0; + + for (let i = 1; i <= 15; i++) { + const ingredient = drink[`strIngredient${i}`]; + if (ingredient && ingredient.trim()) { + ingredientCount++; + const measure = drink[`strMeasure${i}`]?.trim() || ""; + const line = measure ? `${measure} ${ingredient}` : ingredient; + markdown += `- ${line}\n`; + } + } + + if (ingredientCount === 0) { + markdown += `- No ingredients listed\n`; + } + markdown += `\n`; + + // Instructions + markdown += `### Instructions\n${drink.strInstructions || "No instructions provided."}\n\n`; + + // Glass + markdown += `Serve in: ${drink.strGlass || "Unknown"}\n\n`; + + markdown += `---\n\n`; } } - if (ingredientCount === 0) { - markdown += `- No ingredients listed\n`; - } - markdown += `\n`; - - // Instructions - markdown += `### Instructions\n${drink.strInstructions || 'No instructions provided.'}\n\n`; - - // Glass - markdown += `Serve in: ${drink.strGlass || 'Unknown'}\n\n`; - - markdown += `---\n\n`; - } -} - - - -// 3. Write the generated content to a markdown file as given by outPath -await writeFile(outPath, markdown, 'utf-8'); -console.log(`Successfully wrote to ${outPath}`); - + // 3. Write the generated content to a markdown file as given by outPath + await writeFile(outPath, markdown, "utf-8"); + console.log(`Successfully wrote to ${outPath}`); } catch (error) { // 4. Handle errors - console.error(error.message); -} + console.error(error.message); } - +} // Do not change the code below if (!process.env.VITEST) { diff --git a/task-1/output/margarita.md b/task-1/output/margarita.md index 16e2877..00f2ec4 100644 --- a/task-1/output/margarita.md +++ b/task-1/output/margarita.md @@ -15,9 +15,118 @@ - Salt ### Instructions -Rub the rim of the glass. +Rub the rim of the glass with the lime slice to make the salt stick to it. Take care to moisten only the outer rim and sprinkle the salt on it. The salt should present to the lips of the imbiber and never mix into the cocktail. Shake the other ingredients with ice, then carefully pour into the glass. Serve in: Cocktail glass --- +## Blue Margarita + +![Blue Margarita](https://www.thecocktaildb.com/images/media/drink/bry4qh1582751040.jpg/medium) + +**Category**: Ordinary Drink +**Alcoholic**: Yes + +### Ingredients + +- 1 1/2 oz Tequila +- 1 oz Blue Curacao +- 1 oz Lime juice +- Coarse Salt + +### Instructions +Rub rim of cocktail glass with lime juice. Dip rim in coarse salt. Shake tequila, blue curacao, and lime juice with ice, strain into the salt-rimmed glass, and serve. + +Serve in: Cocktail glass + +--- + +## Tommy's Margarita + +![Tommy's Margarita](https://www.thecocktaildb.com/images/media/drink/loezxn1504373874.jpg/medium) + +**Category**: Ordinary Drink +**Alcoholic**: Yes + +### Ingredients + +- 4.5 cl Tequila +- 1.5 cl Lime Juice +- 2 spoons Agave syrup + +### Instructions +Shake and strain into a chilled cocktail glass. + +Serve in: Old-Fashioned glass + +--- + +## Whitecap Margarita + +![Whitecap Margarita](https://www.thecocktaildb.com/images/media/drink/srpxxp1441209622.jpg/medium) + +**Category**: Other / Unknown +**Alcoholic**: Yes + +### Ingredients + +- 1 cup Ice +- 2 oz Tequila +- 1/4 cup Cream of coconut +- 3 tblsp fresh Lime juice + +### Instructions +Place all ingredients in a blender and blend until smooth. This makes one drink. + +Serve in: Margarita/Coupette glass + +--- + +## Strawberry Margarita + +![Strawberry Margarita](https://www.thecocktaildb.com/images/media/drink/tqyrpw1439905311.jpg/medium) + +**Category**: Ordinary Drink +**Alcoholic**: Yes + +### Ingredients + +- 1/2 oz Strawberry schnapps +- 1 oz Tequila +- 1/2 oz Triple sec +- 1 oz Lemon juice +- 1 oz Strawberries +- Salt + +### Instructions +Rub rim of cocktail glass with lemon juice and dip rim in salt. Shake schnapps, tequila, triple sec, lemon juice, and strawberries with ice, strain into the salt-rimmed glass, and serve. + +Serve in: Cocktail glass + +--- + +## Smashed Watermelon Margarita + +![Smashed Watermelon Margarita](https://www.thecocktaildb.com/images/media/drink/dztcv51598717861.jpg/medium) + +**Category**: Cocktail +**Alcoholic**: Yes + +### Ingredients + +- 1/2 cup Watermelon +- 5 Mint +- 1/3 Cup Grapefruit Juice +- Juice of 1/2 Lime +- 1 shot Tequila +- Garnish with Watermelon +- Garnish with Mint + +### Instructions +In a mason jar muddle the watermelon and 5 mint leaves together into a puree and strain. Next add the grapefruit juice, juice of half a lime and the tequila as well as some ice. Put a lid on the jar and shake. Pour into a glass and add more ice. Garnish with fresh mint and a small slice of watermelon. + +Serve in: Collins glass + +--- + From 2cdc3552bd95c8c4265f09301ce1ed4344f77530 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Mar 2026 08:02:02 +0100 Subject: [PATCH 4/6] initialized the project --- package-lock.json | 207 +++++++++++++++++++++++----------------------- 1 file changed, 103 insertions(+), 104 deletions(-) diff --git a/package-lock.json b/package-lock.json index 65aa212..fe4a8f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "core-assignment-week-10", "version": "1.0.0", - "hasInstallScript": true, "license": "CC BY-NC-SA 4.0", "dependencies": { "@inquirer/prompts": "^7.0.0", @@ -802,9 +801,9 @@ "license": "MIT" }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.57.1.tgz", - "integrity": "sha512-A6ehUVSiSaaliTxai040ZpZ2zTevHYbvu/lDoeAteHI8QnaosIzm4qwtezfRg1jOYaUmnzLX1AOD6Z+UJjtifg==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.59.0.tgz", + "integrity": "sha512-upnNBkA6ZH2VKGcBj9Fyl9IGNPULcjXRlg0LLeaioQWueH30p6IXtJEbKAgvyv+mJaMxSm1l6xwDXYjpEMiLMg==", "cpu": [ "arm" ], @@ -816,9 +815,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.57.1.tgz", - "integrity": "sha512-dQaAddCY9YgkFHZcFNS/606Exo8vcLHwArFZ7vxXq4rigo2bb494/xKMMwRRQW6ug7Js6yXmBZhSBRuBvCCQ3w==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.59.0.tgz", + "integrity": "sha512-hZ+Zxj3SySm4A/DylsDKZAeVg0mvi++0PYVceVyX7hemkw7OreKdCvW2oQ3T1FMZvCaQXqOTHb8qmBShoqk69Q==", "cpu": [ "arm64" ], @@ -830,9 +829,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.57.1.tgz", - "integrity": "sha512-crNPrwJOrRxagUYeMn/DZwqN88SDmwaJ8Cvi/TN1HnWBU7GwknckyosC2gd0IqYRsHDEnXf328o9/HC6OkPgOg==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.59.0.tgz", + "integrity": "sha512-W2Psnbh1J8ZJw0xKAd8zdNgF9HRLkdWwwdWqubSVk0pUuQkoHnv7rx4GiF9rT4t5DIZGAsConRE3AxCdJ4m8rg==", "cpu": [ "arm64" ], @@ -844,9 +843,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.57.1.tgz", - "integrity": "sha512-Ji8g8ChVbKrhFtig5QBV7iMaJrGtpHelkB3lsaKzadFBe58gmjfGXAOfI5FV0lYMH8wiqsxKQ1C9B0YTRXVy4w==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.59.0.tgz", + "integrity": "sha512-ZW2KkwlS4lwTv7ZVsYDiARfFCnSGhzYPdiOU4IM2fDbL+QGlyAbjgSFuqNRbSthybLbIJ915UtZBtmuLrQAT/w==", "cpu": [ "x64" ], @@ -858,9 +857,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-arm64": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.57.1.tgz", - "integrity": "sha512-R+/WwhsjmwodAcz65guCGFRkMb4gKWTcIeLy60JJQbXrJ97BOXHxnkPFrP+YwFlaS0m+uWJTstrUA9o+UchFug==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.59.0.tgz", + "integrity": "sha512-EsKaJ5ytAu9jI3lonzn3BgG8iRBjV4LxZexygcQbpiU0wU0ATxhNVEpXKfUa0pS05gTcSDMKpn3Sx+QB9RlTTA==", "cpu": [ "arm64" ], @@ -872,9 +871,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-x64": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.57.1.tgz", - "integrity": "sha512-IEQTCHeiTOnAUC3IDQdzRAGj3jOAYNr9kBguI7MQAAZK3caezRrg0GxAb6Hchg4lxdZEI5Oq3iov/w/hnFWY9Q==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.59.0.tgz", + "integrity": "sha512-d3DuZi2KzTMjImrxoHIAODUZYoUUMsuUiY4SRRcJy6NJoZ6iIqWnJu9IScV9jXysyGMVuW+KNzZvBLOcpdl3Vg==", "cpu": [ "x64" ], @@ -886,9 +885,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.57.1.tgz", - "integrity": "sha512-F8sWbhZ7tyuEfsmOxwc2giKDQzN3+kuBLPwwZGyVkLlKGdV1nvnNwYD0fKQ8+XS6hp9nY7B+ZeK01EBUE7aHaw==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.59.0.tgz", + "integrity": "sha512-t4ONHboXi/3E0rT6OZl1pKbl2Vgxf9vJfWgmUoCEVQVxhW6Cw/c8I6hbbu7DAvgp82RKiH7TpLwxnJeKv2pbsw==", "cpu": [ "arm" ], @@ -900,9 +899,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.57.1.tgz", - "integrity": "sha512-rGfNUfn0GIeXtBP1wL5MnzSj98+PZe/AXaGBCRmT0ts80lU5CATYGxXukeTX39XBKsxzFpEeK+Mrp9faXOlmrw==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.59.0.tgz", + "integrity": "sha512-CikFT7aYPA2ufMD086cVORBYGHffBo4K8MQ4uPS/ZnY54GKj36i196u8U+aDVT2LX4eSMbyHtyOh7D7Zvk2VvA==", "cpu": [ "arm" ], @@ -914,9 +913,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.57.1.tgz", - "integrity": "sha512-MMtej3YHWeg/0klK2Qodf3yrNzz6CGjo2UntLvk2RSPlhzgLvYEB3frRvbEF2wRKh1Z2fDIg9KRPe1fawv7C+g==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.59.0.tgz", + "integrity": "sha512-jYgUGk5aLd1nUb1CtQ8E+t5JhLc9x5WdBKew9ZgAXg7DBk0ZHErLHdXM24rfX+bKrFe+Xp5YuJo54I5HFjGDAA==", "cpu": [ "arm64" ], @@ -928,9 +927,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.57.1.tgz", - "integrity": "sha512-1a/qhaaOXhqXGpMFMET9VqwZakkljWHLmZOX48R0I/YLbhdxr1m4gtG1Hq7++VhVUmf+L3sTAf9op4JlhQ5u1Q==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.59.0.tgz", + "integrity": "sha512-peZRVEdnFWZ5Bh2KeumKG9ty7aCXzzEsHShOZEFiCQlDEepP1dpUl/SrUNXNg13UmZl+gzVDPsiCwnV1uI0RUA==", "cpu": [ "arm64" ], @@ -942,9 +941,9 @@ ] }, "node_modules/@rollup/rollup-linux-loong64-gnu": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.57.1.tgz", - "integrity": "sha512-QWO6RQTZ/cqYtJMtxhkRkidoNGXc7ERPbZN7dVW5SdURuLeVU7lwKMpo18XdcmpWYd0qsP1bwKPf7DNSUinhvA==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.59.0.tgz", + "integrity": "sha512-gbUSW/97f7+r4gHy3Jlup8zDG190AuodsWnNiXErp9mT90iCy9NKKU0Xwx5k8VlRAIV2uU9CsMnEFg/xXaOfXg==", "cpu": [ "loong64" ], @@ -956,9 +955,9 @@ ] }, "node_modules/@rollup/rollup-linux-loong64-musl": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.57.1.tgz", - "integrity": "sha512-xpObYIf+8gprgWaPP32xiN5RVTi/s5FCR+XMXSKmhfoJjrpRAjCuuqQXyxUa/eJTdAE6eJ+KDKaoEqjZQxh3Gw==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.59.0.tgz", + "integrity": "sha512-yTRONe79E+o0FWFijasoTjtzG9EBedFXJMl888NBEDCDV9I2wGbFFfJQQe63OijbFCUZqxpHz1GzpbtSFikJ4Q==", "cpu": [ "loong64" ], @@ -970,9 +969,9 @@ ] }, "node_modules/@rollup/rollup-linux-ppc64-gnu": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.57.1.tgz", - "integrity": "sha512-4BrCgrpZo4hvzMDKRqEaW1zeecScDCR+2nZ86ATLhAoJ5FQ+lbHVD3ttKe74/c7tNT9c6F2viwB3ufwp01Oh2w==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.59.0.tgz", + "integrity": "sha512-sw1o3tfyk12k3OEpRddF68a1unZ5VCN7zoTNtSn2KndUE+ea3m3ROOKRCZxEpmT9nsGnogpFP9x6mnLTCaoLkA==", "cpu": [ "ppc64" ], @@ -984,9 +983,9 @@ ] }, "node_modules/@rollup/rollup-linux-ppc64-musl": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.57.1.tgz", - "integrity": "sha512-NOlUuzesGauESAyEYFSe3QTUguL+lvrN1HtwEEsU2rOwdUDeTMJdO5dUYl/2hKf9jWydJrO9OL/XSSf65R5+Xw==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.59.0.tgz", + "integrity": "sha512-+2kLtQ4xT3AiIxkzFVFXfsmlZiG5FXYW7ZyIIvGA7Bdeuh9Z0aN4hVyXS/G1E9bTP/vqszNIN/pUKCk/BTHsKA==", "cpu": [ "ppc64" ], @@ -998,9 +997,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.57.1.tgz", - "integrity": "sha512-ptA88htVp0AwUUqhVghwDIKlvJMD/fmL/wrQj99PRHFRAG6Z5nbWoWG4o81Nt9FT+IuqUQi+L31ZKAFeJ5Is+A==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.59.0.tgz", + "integrity": "sha512-NDYMpsXYJJaj+I7UdwIuHHNxXZ/b/N2hR15NyH3m2qAtb/hHPA4g4SuuvrdxetTdndfj9b1WOmy73kcPRoERUg==", "cpu": [ "riscv64" ], @@ -1012,9 +1011,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-musl": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.57.1.tgz", - "integrity": "sha512-S51t7aMMTNdmAMPpBg7OOsTdn4tySRQvklmL3RpDRyknk87+Sp3xaumlatU+ppQ+5raY7sSTcC2beGgvhENfuw==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.59.0.tgz", + "integrity": "sha512-nLckB8WOqHIf1bhymk+oHxvM9D3tyPndZH8i8+35p/1YiVoVswPid2yLzgX7ZJP0KQvnkhM4H6QZ5m0LzbyIAg==", "cpu": [ "riscv64" ], @@ -1026,9 +1025,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.57.1.tgz", - "integrity": "sha512-Bl00OFnVFkL82FHbEqy3k5CUCKH6OEJL54KCyx2oqsmZnFTR8IoNqBF+mjQVcRCT5sB6yOvK8A37LNm/kPJiZg==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.59.0.tgz", + "integrity": "sha512-oF87Ie3uAIvORFBpwnCvUzdeYUqi2wY6jRFWJAy1qus/udHFYIkplYRW+wo+GRUP4sKzYdmE1Y3+rY5Gc4ZO+w==", "cpu": [ "s390x" ], @@ -1040,9 +1039,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.57.1.tgz", - "integrity": "sha512-ABca4ceT4N+Tv/GtotnWAeXZUZuM/9AQyCyKYyKnpk4yoA7QIAuBt6Hkgpw8kActYlew2mvckXkvx0FfoInnLg==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.59.0.tgz", + "integrity": "sha512-3AHmtQq/ppNuUspKAlvA8HtLybkDflkMuLK4DPo77DfthRb71V84/c4MlWJXixZz4uruIH4uaa07IqoAkG64fg==", "cpu": [ "x64" ], @@ -1054,9 +1053,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.57.1.tgz", - "integrity": "sha512-HFps0JeGtuOR2convgRRkHCekD7j+gdAuXM+/i6kGzQtFhlCtQkpwtNzkNj6QhCDp7DRJ7+qC/1Vg2jt5iSOFw==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.59.0.tgz", + "integrity": "sha512-2UdiwS/9cTAx7qIUZB/fWtToJwvt0Vbo0zmnYt7ED35KPg13Q0ym1g442THLC7VyI6JfYTP4PiSOWyoMdV2/xg==", "cpu": [ "x64" ], @@ -1068,9 +1067,9 @@ ] }, "node_modules/@rollup/rollup-openbsd-x64": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.57.1.tgz", - "integrity": "sha512-H+hXEv9gdVQuDTgnqD+SQffoWoc0Of59AStSzTEj/feWTBAnSfSD3+Dql1ZruJQxmykT/JVY0dE8Ka7z0DH1hw==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.59.0.tgz", + "integrity": "sha512-M3bLRAVk6GOwFlPTIxVBSYKUaqfLrn8l0psKinkCFxl4lQvOSz8ZrKDz2gxcBwHFpci0B6rttydI4IpS4IS/jQ==", "cpu": [ "x64" ], @@ -1082,9 +1081,9 @@ ] }, "node_modules/@rollup/rollup-openharmony-arm64": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.57.1.tgz", - "integrity": "sha512-4wYoDpNg6o/oPximyc/NG+mYUejZrCU2q+2w6YZqrAs2UcNUChIZXjtafAiiZSUc7On8v5NyNj34Kzj/Ltk6dQ==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.59.0.tgz", + "integrity": "sha512-tt9KBJqaqp5i5HUZzoafHZX8b5Q2Fe7UjYERADll83O4fGqJ49O1FsL6LpdzVFQcpwvnyd0i+K/VSwu/o/nWlA==", "cpu": [ "arm64" ], @@ -1096,9 +1095,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.57.1.tgz", - "integrity": "sha512-O54mtsV/6LW3P8qdTcamQmuC990HDfR71lo44oZMZlXU4tzLrbvTii87Ni9opq60ds0YzuAlEr/GNwuNluZyMQ==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.59.0.tgz", + "integrity": "sha512-V5B6mG7OrGTwnxaNUzZTDTjDS7F75PO1ae6MJYdiMu60sq0CqN5CVeVsbhPxalupvTX8gXVSU9gq+Rx1/hvu6A==", "cpu": [ "arm64" ], @@ -1110,9 +1109,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.57.1.tgz", - "integrity": "sha512-P3dLS+IerxCT/7D2q2FYcRdWRl22dNbrbBEtxdWhXrfIMPP9lQhb5h4Du04mdl5Woq05jVCDPCMF7Ub0NAjIew==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.59.0.tgz", + "integrity": "sha512-UKFMHPuM9R0iBegwzKF4y0C4J9u8C6MEJgFuXTBerMk7EJ92GFVFYBfOZaSGLu6COf7FxpQNqhNS4c4icUPqxA==", "cpu": [ "ia32" ], @@ -1124,9 +1123,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-gnu": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.57.1.tgz", - "integrity": "sha512-VMBH2eOOaKGtIJYleXsi2B8CPVADrh+TyNxJ4mWPnKfLB/DBUmzW+5m1xUrcwWoMfSLagIRpjUFeW5CO5hyciQ==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.59.0.tgz", + "integrity": "sha512-laBkYlSS1n2L8fSo1thDNGrCTQMmxjYY5G0WFWjFFYZkKPjsMBsgJfGf4TLxXrF6RyhI60L8TMOjBMvXiTcxeA==", "cpu": [ "x64" ], @@ -1138,9 +1137,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.57.1.tgz", - "integrity": "sha512-mxRFDdHIWRxg3UfIIAwCm6NzvxG0jDX/wBN6KsQFTvKFqqg9vTrWUE68qEjHt19A5wwx5X5aUi2zuZT7YR0jrA==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.59.0.tgz", + "integrity": "sha512-2HRCml6OztYXyJXAvdDXPKcawukWY2GpR5/nxKp4iBgiO3wcoEGkAaqctIbZcNB6KlUQBIqt8VYkNSj2397EfA==", "cpu": [ "x64" ], @@ -1632,9 +1631,9 @@ } }, "node_modules/rollup": { - "version": "4.57.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.57.1.tgz", - "integrity": "sha512-oQL6lgK3e2QZeQ7gcgIkS2YZPg5slw37hYufJ3edKlfQSGGm8ICoxswK15ntSzF/a8+h7ekRy7k7oWc3BQ7y8A==", + "version": "4.59.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.59.0.tgz", + "integrity": "sha512-2oMpl67a3zCH9H79LeMcbDhXW/UmWG/y2zuqnF2jQq5uq9TbM9TVyXvA4+t+ne2IIkBdrLpAaRQAvo7YI/Yyeg==", "dev": true, "license": "MIT", "dependencies": { @@ -1648,31 +1647,31 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.57.1", - "@rollup/rollup-android-arm64": "4.57.1", - "@rollup/rollup-darwin-arm64": "4.57.1", - "@rollup/rollup-darwin-x64": "4.57.1", - "@rollup/rollup-freebsd-arm64": "4.57.1", - "@rollup/rollup-freebsd-x64": "4.57.1", - "@rollup/rollup-linux-arm-gnueabihf": "4.57.1", - "@rollup/rollup-linux-arm-musleabihf": "4.57.1", - "@rollup/rollup-linux-arm64-gnu": "4.57.1", - "@rollup/rollup-linux-arm64-musl": "4.57.1", - "@rollup/rollup-linux-loong64-gnu": "4.57.1", - "@rollup/rollup-linux-loong64-musl": "4.57.1", - "@rollup/rollup-linux-ppc64-gnu": "4.57.1", - "@rollup/rollup-linux-ppc64-musl": "4.57.1", - "@rollup/rollup-linux-riscv64-gnu": "4.57.1", - "@rollup/rollup-linux-riscv64-musl": "4.57.1", - "@rollup/rollup-linux-s390x-gnu": "4.57.1", - "@rollup/rollup-linux-x64-gnu": "4.57.1", - "@rollup/rollup-linux-x64-musl": "4.57.1", - "@rollup/rollup-openbsd-x64": "4.57.1", - "@rollup/rollup-openharmony-arm64": "4.57.1", - "@rollup/rollup-win32-arm64-msvc": "4.57.1", - "@rollup/rollup-win32-ia32-msvc": "4.57.1", - "@rollup/rollup-win32-x64-gnu": "4.57.1", - "@rollup/rollup-win32-x64-msvc": "4.57.1", + "@rollup/rollup-android-arm-eabi": "4.59.0", + "@rollup/rollup-android-arm64": "4.59.0", + "@rollup/rollup-darwin-arm64": "4.59.0", + "@rollup/rollup-darwin-x64": "4.59.0", + "@rollup/rollup-freebsd-arm64": "4.59.0", + "@rollup/rollup-freebsd-x64": "4.59.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.59.0", + "@rollup/rollup-linux-arm-musleabihf": "4.59.0", + "@rollup/rollup-linux-arm64-gnu": "4.59.0", + "@rollup/rollup-linux-arm64-musl": "4.59.0", + "@rollup/rollup-linux-loong64-gnu": "4.59.0", + "@rollup/rollup-linux-loong64-musl": "4.59.0", + "@rollup/rollup-linux-ppc64-gnu": "4.59.0", + "@rollup/rollup-linux-ppc64-musl": "4.59.0", + "@rollup/rollup-linux-riscv64-gnu": "4.59.0", + "@rollup/rollup-linux-riscv64-musl": "4.59.0", + "@rollup/rollup-linux-s390x-gnu": "4.59.0", + "@rollup/rollup-linux-x64-gnu": "4.59.0", + "@rollup/rollup-linux-x64-musl": "4.59.0", + "@rollup/rollup-openbsd-x64": "4.59.0", + "@rollup/rollup-openharmony-arm64": "4.59.0", + "@rollup/rollup-win32-arm64-msvc": "4.59.0", + "@rollup/rollup-win32-ia32-msvc": "4.59.0", + "@rollup/rollup-win32-x64-gnu": "4.59.0", + "@rollup/rollup-win32-x64-msvc": "4.59.0", "fsevents": "~2.3.2" } }, From 315c62c7729c4ba2ba2c05cfad31310e7e963101 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Mar 2026 19:09:55 +0100 Subject: [PATCH 5/6] fixed the backtick issue --- task-2/post-cli/src/services.js | 110 ++++++++++++++++++++++-- task-2/post-cli/tests/test-crud.test.js | 6 +- 2 files changed, 110 insertions(+), 6 deletions(-) diff --git a/task-2/post-cli/src/services.js b/task-2/post-cli/src/services.js index 2601f57..df634b2 100644 --- a/task-2/post-cli/src/services.js +++ b/task-2/post-cli/src/services.js @@ -1,5 +1,5 @@ // Change base URL for API requests to the local IP of the Post Central API server -const BASE_URL = 'http://localhost:3000'; +const BASE_URL = "http://localhost:3000"; // ============================================================================ // AUTH TOKEN - Stored after login/register, sent with every request @@ -37,7 +37,7 @@ const getHello = async () => { const response = await fetch(`${BASE_URL}/posts/hello`); if (!response.ok) { throw new Error( - `Failed to get hello: HTTP ${response.status} ${response.statusText}` + `Failed to get hello: HTTP ${response.status} ${response.statusText}`, ); } return await response.json(); @@ -54,6 +54,22 @@ const getHello = async () => { */ const getMe = async () => { // TODO + const response = await fetch(`${BASE_URL}/users/me`, { + /** + * + */ + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${getToken()}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to get user: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; // ============================================================================ @@ -68,15 +84,15 @@ const getMe = async () => { */ const createUser = async (name, password) => { const response = await fetch(`${BASE_URL}/users/register`, { - method: 'POST', + method: `POST`, headers: { - 'Content-Type': 'application/json', + "Content-Type": `application/json`, }, body: JSON.stringify({ name, password }), }); if (!response.ok) { throw new Error( - `Failed to create user: HTTP ${response.status} ${response.statusText}` + `Failed to create user: HTTP ${response.status} ${response.statusText}`, ); } return await response.json(); @@ -90,6 +106,19 @@ const createUser = async (name, password) => { */ const loginUser = async (name, password) => { // TODO + const response = await fetch(`${BASE_URL}/users/login`, { + method: "POST", + headers: { + "Content-Type": `application/json`, + }, + body: JSON.stringify({ name, password }), + }); + if (!response.ok) { + throw new Error( + `Failed to create user: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; // ============================================================================ @@ -104,6 +133,20 @@ const loginUser = async (name, password) => { */ const createPost = async (text) => { // TODO + const response = await fetch(`${BASE_URL}/posts`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${getToken()}`, + }, + body: JSON.stringify({ text }), + }); + if (!response.ok) + throw new Error( + `Failed to get user: HTTP ${response.status} ${response.statusText}`, + ); + + return await response.json(); }; /** @@ -113,6 +156,22 @@ const createPost = async (text) => { */ const getPosts = async () => { // TODO + const response = await fetch(`${BASE_URL}/posts/me`, { + /** + * + */ + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${getToken()}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to get user: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; /** @@ -123,6 +182,21 @@ const getPosts = async () => { */ const updatePost = async (id, text) => { // TODO + const response = await fetch(`${BASE_URL}/posts/${id}`, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${getToken()}`, + }, + body: JSON.stringify({ text }), + + }); + if (!response.ok) { + throw new Error( + `Failed to get user: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; /** @@ -132,6 +206,19 @@ const updatePost = async (id, text) => { */ const deleteUser = async () => { // TODO + const response = await fetch(`${BASE_URL}/users/me`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${getToken()}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to get user: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; /** @@ -141,6 +228,19 @@ const deleteUser = async () => { */ const deletePost = async (id) => { // TODO + const response = await fetch(`${BASE_URL}/posts/${id}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${getToken()}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to delete post: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; // ============================================================================ diff --git a/task-2/post-cli/tests/test-crud.test.js b/task-2/post-cli/tests/test-crud.test.js index fbf7ea4..2d15c98 100644 --- a/task-2/post-cli/tests/test-crud.test.js +++ b/task-2/post-cli/tests/test-crud.test.js @@ -152,6 +152,7 @@ describe('Complete CRUD Operations', () => { fetchMock.mockResolvedValueOnce({ ok: true, status: 200, + json: async () => ({ id: 1, text: 'Updated post text!', message: 'Post deleted' }), }); // DELETE: Remove the post @@ -170,6 +171,7 @@ describe('Complete CRUD Operations', () => { fetchMock.mockResolvedValueOnce({ ok: true, status: 200, + json: async () => ({ user: 'Alice', message: 'User deleted' }), }); // DELETE: Remove the user @@ -218,6 +220,7 @@ describe('Complete CRUD Operations', () => { fetchMock.mockResolvedValueOnce({ ok: true, status: 200, + json: async () => ({ user: 'mock-user', message: 'User deleted' }), }); await deleteUser(); @@ -240,6 +243,7 @@ describe('Complete CRUD Operations', () => { fetchMock.mockResolvedValueOnce({ ok: true, status: 200, + json: async () => ({ id: 5, text: 'some text', message: 'Post deleted' }), }); await deletePost(5); @@ -292,4 +296,4 @@ describe('Complete CRUD Operations', () => { // Verify any function throws error on API failure await expect(createUser('Test', 'pass')).rejects.toThrow(); }); -}); +}); \ No newline at end of file From 1771714ed71506b9cb187968c64bc025b708efd0 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Mar 2026 19:11:52 +0100 Subject: [PATCH 6/6] compared results to examples given --- task-1/output/margarita.md | 111 +------------------------------------ 1 file changed, 1 insertion(+), 110 deletions(-) diff --git a/task-1/output/margarita.md b/task-1/output/margarita.md index 00f2ec4..16e2877 100644 --- a/task-1/output/margarita.md +++ b/task-1/output/margarita.md @@ -15,118 +15,9 @@ - Salt ### Instructions -Rub the rim of the glass with the lime slice to make the salt stick to it. Take care to moisten only the outer rim and sprinkle the salt on it. The salt should present to the lips of the imbiber and never mix into the cocktail. Shake the other ingredients with ice, then carefully pour into the glass. +Rub the rim of the glass. Serve in: Cocktail glass --- -## Blue Margarita - -![Blue Margarita](https://www.thecocktaildb.com/images/media/drink/bry4qh1582751040.jpg/medium) - -**Category**: Ordinary Drink -**Alcoholic**: Yes - -### Ingredients - -- 1 1/2 oz Tequila -- 1 oz Blue Curacao -- 1 oz Lime juice -- Coarse Salt - -### Instructions -Rub rim of cocktail glass with lime juice. Dip rim in coarse salt. Shake tequila, blue curacao, and lime juice with ice, strain into the salt-rimmed glass, and serve. - -Serve in: Cocktail glass - ---- - -## Tommy's Margarita - -![Tommy's Margarita](https://www.thecocktaildb.com/images/media/drink/loezxn1504373874.jpg/medium) - -**Category**: Ordinary Drink -**Alcoholic**: Yes - -### Ingredients - -- 4.5 cl Tequila -- 1.5 cl Lime Juice -- 2 spoons Agave syrup - -### Instructions -Shake and strain into a chilled cocktail glass. - -Serve in: Old-Fashioned glass - ---- - -## Whitecap Margarita - -![Whitecap Margarita](https://www.thecocktaildb.com/images/media/drink/srpxxp1441209622.jpg/medium) - -**Category**: Other / Unknown -**Alcoholic**: Yes - -### Ingredients - -- 1 cup Ice -- 2 oz Tequila -- 1/4 cup Cream of coconut -- 3 tblsp fresh Lime juice - -### Instructions -Place all ingredients in a blender and blend until smooth. This makes one drink. - -Serve in: Margarita/Coupette glass - ---- - -## Strawberry Margarita - -![Strawberry Margarita](https://www.thecocktaildb.com/images/media/drink/tqyrpw1439905311.jpg/medium) - -**Category**: Ordinary Drink -**Alcoholic**: Yes - -### Ingredients - -- 1/2 oz Strawberry schnapps -- 1 oz Tequila -- 1/2 oz Triple sec -- 1 oz Lemon juice -- 1 oz Strawberries -- Salt - -### Instructions -Rub rim of cocktail glass with lemon juice and dip rim in salt. Shake schnapps, tequila, triple sec, lemon juice, and strawberries with ice, strain into the salt-rimmed glass, and serve. - -Serve in: Cocktail glass - ---- - -## Smashed Watermelon Margarita - -![Smashed Watermelon Margarita](https://www.thecocktaildb.com/images/media/drink/dztcv51598717861.jpg/medium) - -**Category**: Cocktail -**Alcoholic**: Yes - -### Ingredients - -- 1/2 cup Watermelon -- 5 Mint -- 1/3 Cup Grapefruit Juice -- Juice of 1/2 Lime -- 1 shot Tequila -- Garnish with Watermelon -- Garnish with Mint - -### Instructions -In a mason jar muddle the watermelon and 5 mint leaves together into a puree and strain. Next add the grapefruit juice, juice of half a lime and the tequila as well as some ice. Put a lid on the jar and shake. Pour into a glass and add more ice. Garnish with fresh mint and a small slice of watermelon. - -Serve in: Collins glass - ---- -