From 8b4a65a2339863e1a0adae75bf3f3eedadca58c2 Mon Sep 17 00:00:00 2001 From: Salem Ba-rabuod Date: Wed, 18 Mar 2026 22:12:41 +0100 Subject: [PATCH] solved the assignment --- package-lock.json | 3 - task-1/cocktail.js | 58 ++++- task-1/output/Martini.md | 318 ++++++++++++++++++++++++ task-1/output/margarit.md | 137 ++++++++++ task-1/output/margarita.md | 22 ++ task-2/post-cli/package-lock.json | 5 +- task-2/post-cli/src/services.js | 100 +++++++- task-2/post-cli/tests/test-crud.test.js | 28 ++- 8 files changed, 641 insertions(+), 30 deletions(-) create mode 100644 task-1/output/Martini.md create mode 100644 task-1/output/margarit.md create mode 100644 task-1/output/margarita.md diff --git a/package-lock.json b/package-lock.json index 65aa212..a26d152 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", @@ -1585,7 +1584,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -1822,7 +1820,6 @@ "integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", diff --git a/task-1/cocktail.js b/task-1/cocktail.js index 6fd5a62..2be22ed 100644 --- a/task-1/cocktail.js +++ b/task-1/cocktail.js @@ -1,11 +1,50 @@ // API documentation: https://www.thecocktaildb.com/api.php import path from 'path'; +import fs from 'node:fs'; const BASE_URL = 'https://www.thecocktaildb.com/api/json/v1/1'; // Add helper functions as needed here +function generateMarkdown(cocktail) { + let markdown = `# Cocktail Recipes`; + + for (const drink of cocktail.drinks) { + const ingredients = []; + for (let i = 1; i <= 15; i++) { + const ingredient = drink[`strIngredient${i}`]; + const measure = drink[`strMeasure${i}`]; + if (ingredient) { + ingredients.push( + `- ${measure ? measure.trim() + ' ' : ''}${ingredient.trim()}`, + ); + } + } + markdown += ` + +## ${drink.strDrink} + +![${drink.strDrink}](${drink.strDrinkThumb}/medium) + +**Category**: ${drink.strCategory} + +**Alcoholic**: ${drink.strAlcoholic === 'Alcoholic' ? 'Yes' : 'No'} + +### Ingredients + +${ingredients.join('\n')} + +### Instructions + +${drink.strInstructions} + +Serve in: ${drink.strGlass}`; + } + + return markdown; +} + export async function main() { if (process.argv.length < 3) { console.error('Please provide a cocktail name as a command line argument.'); @@ -19,11 +58,22 @@ export async function main() { const outPath = path.join(__dirname, `./output/${cocktailName}.md`); try { - // 1. Fetch data from the API at the given URL - // 2. Generate markdown content to match the examples - // 3. Write the generated content to a markdown file as given by outPath + const response = await fetch(url); + if (!response.ok) { + throw new Error(`Request failed with status ${response.status}`); + } + + const data = await response.json(); + if (data.drinks === null) { + throw new Error('No cocktails found with that name.'); + } + + const markdown = generateMarkdown(data); + + fs.writeFileSync(outPath, markdown); + console.log(`Successfully created: ${cocktailName}`); } catch (error) { - // 4. Handle errors + console.error(error.message); } } diff --git a/task-1/output/Martini.md b/task-1/output/Martini.md new file mode 100644 index 0000000..24e5c6f --- /dev/null +++ b/task-1/output/Martini.md @@ -0,0 +1,318 @@ +# Cocktail Recipes + +## Martini + +![Martini](https://www.thecocktaildb.com/images/media/drink/71t8581504353095.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1 2/3 ozGin +- 1/3 ozDry Vermouth +- 1Olive + + +### Instructions + +Straight: Pour all ingredients into mixing glass with ice cubes. Stir well. Strain in chilled martini cocktail glass. Squeeze oil from lemon peel onto the drink, or garnish with olive. + +Serve in: Cocktail glass + +## Dry Martini + +![Dry Martini](https://www.thecocktaildb.com/images/media/drink/6ck9yi1589574317.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1 2/3 ozGin +- 1/3 ozDry Vermouth +- 1Olive + + +### Instructions + +Straight: Pour all ingredients into mixing glass with ice cubes. Stir well. Strain in chilled martini cocktail glass. Squeeze oil from lemon peel onto the drink, or garnish with olive. + +Serve in: Cocktail glass + +## Kiwi Martini + +![Kiwi Martini](https://www.thecocktaildb.com/images/media/drink/bmxmyq1630407098.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1/2Kiwi +- 1 tspSugar Syrup +- 1 1/2 ozVodka +- Garnish withKiwi + + +### Instructions + +The kiwi martini is a very fun vodka cocktail and it is one of the best drinks that makes use of fresh fruit. Though there are a few recipes floating around, this is one of the easiest and it is an absolutely delightful green martini to drink. + +For this recipe, you'll simply muddle slices of kiwi with simple syrup, then shake it with vodka. It's a drink that anyone can mix up in minutes and a perfect cocktail to show off your favorite vodka. + +Serve in: Cocktail glass + +## Vodka Martini + +![Vodka Martini](https://www.thecocktaildb.com/images/media/drink/qyxrqw1439906528.jpg/medium) + +**Category**: Ordinary Drink + +**Alcoholic**: Yes + +### Ingredients + +- 1 1/2 ozVodka +- 3/4 ozDry Vermouth +- 1Olive + + +### Instructions + +Shake the vodka and vermouth together with a number of ice cubes, strain into a cocktail glass, add the olive and serve. + +Serve in: Cocktail glass + +## Dirty Martini + +![Dirty Martini](https://www.thecocktaildb.com/images/media/drink/vcyvpq1485083300.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 70ml/2fl ozVodka +- 1 tbspDry Vermouth +- 2 tbspOlive Brine +- 1 wedgeLemon +- 1Olive + + +### Instructions + +Pour the vodka, dry vermouth and olive brine into a cocktail shaker with a handful of ice and shake well. +Rub the rim of a martini glass with the wedge of lemon. +Strain the contents of the cocktail shaker into the glass and add the olive. +A dirty Martini contains a splash of olive brine or olive juice and is typically garnished with an olive. + +Serve in: Cocktail glass + +## Abbey Martini + +![Abbey Martini](https://www.thecocktaildb.com/images/media/drink/2mcozt1504817403.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 2 shotsGin +- 1 shotSweet Vermouth +- 1 shotOrange Juice +- 3 dashesAngostura Bitters + + +### Instructions + +Put all ingredients into a shaker and mix, then strain contents into a chilled cocktail glass. + +Serve in: Cocktail glass + +## French Martini + +![French Martini](https://www.thecocktaildb.com/images/media/drink/clth721504373134.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 4.5 clVodka +- 1.5 clRaspberry Liqueur +- 1.5 clpineapple juice + + +### Instructions + +Pour all ingredients into shaker with ice cubes. Shake well and strain into a chilled cocktail glass. Squeeze oil from lemon peel onto the drink. + +Serve in: Cocktail glass + +## Bellini Martini + +![Bellini Martini](https://www.thecocktaildb.com/images/media/drink/3h9wv51504389379.jpg/medium) + +**Category**: Ordinary Drink + +**Alcoholic**: Yes + +### Ingredients + +- 8 cubesIce +- 3 ozVodka +- 1.5 ozPeach nectar +- 1.5 ozPeach schnapps +- 1Lemon peel + + +### Instructions + +Add ice cubes to shaker. +Add vodka. +Add peach schnapps. +Add peach nectar. +Shake. +Strain into glass. +Add lemon twist peel. + +Serve in: Cocktail glass + +## Espresso Martini + +![Espresso Martini](https://www.thecocktaildb.com/images/media/drink/n0sx531504372951.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 5 clVodka +- 1 clKahlua +- 1 dashSugar syrup + + +### Instructions + +Pour ingredients into shaker filled with ice, shake vigorously, and strain into chilled martini glass + +Serve in: Cocktail glass + +## Pornstar Martini + +![Pornstar Martini](https://www.thecocktaildb.com/images/media/drink/xjhjdf1630406071.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 3 clVodka +- 3 clPassoa +- 1 clPassion fruit juice +- 1 clLime +- 1 shotProsecco + + +### Instructions + +Straight: Pour all ingredients into mixing glass with ice cubes. Shake well. Strain in chilled martini cocktail glass. Cut passion fruit in half and use as garnish. Pour prosecco into a chilled shot glass and serve alongside the martini. + +Serve in: Cocktail glass + +## Cosmopolitan Martini + +![Cosmopolitan Martini](https://www.thecocktaildb.com/images/media/drink/upxxpq1439907580.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1/2 ozCointreau +- 1 ozVodka +- Juice of 1/2Lime +- 1 splashCranberry juice + + +### Instructions + +Pour all ingredients in mixing glass half filled with ice, shake and strain into chilled Martini glass. + +Serve in: Cocktail Glass + +## Salted Toffee Martini + +![Salted Toffee Martini](https://www.thecocktaildb.com/images/media/drink/3s6mlr1509551211.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 50 mlGin +- 30 mlChocolate liqueur +- 15 mlAmaretto +- GarnishChocolate Sauce +- GratedSalted Chocolate + + +### Instructions + +Add ice, toffee gin, chocolate liqueur and Amaretto to a cocktail shaker and shake vigorously. +Pour the chocolate syrup into a saucer and dip the top of a martini glass into the sauce. Grate some of the Willie\'s sea salt chocolate into another saucer and dip the coated glass, so the flakes stick to the sauce, creating a chocolate rim! +Pour the contents of the shaker into your chocolatey glass and sprinkle with more grated chocolate - enjoy! + +Serve in: Cocktail glass + +## Passion Fruit Martini + +![Passion Fruit Martini](https://www.thecocktaildb.com/images/media/drink/6trfve1582473527.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1 shotVodka +- 1/2 shotSugar Syrup +- Full GlassPassion fruit juice + + +### Instructions + +Pour all ingredients into a glass and stir. Garnish with half a passion fruit piece. + +Serve in: Cocktail glass + +## Ziemes Martini Apfelsaft + +![Ziemes Martini Apfelsaft](https://www.thecocktaildb.com/images/media/drink/xnzr2p1485619687.jpg/medium) + +**Category**: Ordinary Drink + +**Alcoholic**: Yes + +### Ingredients + +- 4 clVermouth +- 16 clApple juice + + +### Instructions + +Serve without ice. At least the juice shold have room temperature. + +Serve in: Collins Glass \ No newline at end of file diff --git a/task-1/output/margarit.md b/task-1/output/margarit.md new file mode 100644 index 0000000..0f197f2 --- /dev/null +++ b/task-1/output/margarit.md @@ -0,0 +1,137 @@ +# 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 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 clTequila +- 1.5 clLime Juice +- 2 spoonsAgave 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 cupWatermelon +- 5Mint +- 1/3 CupGrapefruit Juice +- Juice of 1/2Lime +- 1 shotTequila +- Garnish withWatermelon +- Garnish withMint + + +### 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 \ No newline at end of file diff --git a/task-1/output/margarita.md b/task-1/output/margarita.md new file mode 100644 index 0000000..8011a1b --- /dev/null +++ b/task-1/output/margarita.md @@ -0,0 +1,22 @@ +# 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 \ No newline at end of file diff --git a/task-2/post-cli/package-lock.json b/task-2/post-cli/package-lock.json index 8c03ed4..8071efc 100644 --- a/task-2/post-cli/package-lock.json +++ b/task-2/post-cli/package-lock.json @@ -7,8 +7,7 @@ "": { "name": "post-central-cli", "version": "1.0.0", - "hasInstallScript": true, - "license": "ISC", + "license": "CC BY-NC-SA 4.0", "dependencies": { "@inquirer/prompts": "^7.0.0", "chalk": "^5.6.2", @@ -1585,7 +1584,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -1822,7 +1820,6 @@ "integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", diff --git a/task-2/post-cli/src/services.js b/task-2/post-cli/src/services.js index 2601f57..14cb6a2 100644 --- a/task-2/post-cli/src/services.js +++ b/task-2/post-cli/src/services.js @@ -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(); @@ -53,7 +53,18 @@ const getHello = async () => { * Response: { user: string } */ const getMe = async () => { - // TODO + const response = await fetch(`${BASE_URL}/users/me`, { + method: 'GET', + headers: { + Authorization: `Bearer ${getToken()}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to get user info: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; // ============================================================================ @@ -76,7 +87,7 @@ const createUser = async (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(); @@ -89,7 +100,19 @@ const createUser = async (name, password) => { * Response: { user: string, token: string } */ 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 login user: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; // ============================================================================ @@ -103,7 +126,20 @@ const loginUser = async (name, password) => { * Response: { id: number, text: string, user: string } */ 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 create post: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; /** @@ -112,7 +148,18 @@ const createPost = async (text) => { * Response: Array of { id, text, user } */ const getPosts = async () => { - // TODO + const response = await fetch(`${BASE_URL}/posts/me`, { + method: 'GET', + headers: { + Authorization: `Bearer ${getToken()}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to get posts: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; /** @@ -122,7 +169,20 @@ const getPosts = async () => { * Response: { id: number, text: string } */ 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 update post: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; /** @@ -131,7 +191,18 @@ const updatePost = async (id, text) => { * Response: { user: string, message: string } */ const deleteUser = async () => { - // TODO + const response = await fetch(`${BASE_URL}/users/me`, { + method: 'DELETE', + headers: { + Authorization: `Bearer ${getToken()}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to delete user: HTTP ${response.status} ${response.statusText}`, + ); + } + return await response.json(); }; /** @@ -140,7 +211,18 @@ const deleteUser = async () => { * Response: { id: number, text: string, message: string } */ const deletePost = async (id) => { - // TODO + const response = await fetch(`${BASE_URL}/posts/${id}`, { + method: 'DELETE', + headers: { + 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..b4334f5 100644 --- a/task-2/post-cli/tests/test-crud.test.js +++ b/task-2/post-cli/tests/test-crud.test.js @@ -63,7 +63,7 @@ describe('Complete CRUD Operations', () => { expect.objectContaining({ method: 'POST', body: JSON.stringify({ name: testUser, password: testPassword }), - }) + }), ); // Set token for subsequent authenticated requests @@ -88,7 +88,7 @@ describe('Complete CRUD Operations', () => { Authorization: 'Bearer jwt-token-abc', }), body: JSON.stringify({ text: postText }), - }) + }), ); // Mock READ posts response @@ -109,7 +109,7 @@ describe('Complete CRUD Operations', () => { headers: expect.objectContaining({ Authorization: 'Bearer jwt-token-abc', }), - }) + }), ); // Mock UPDATE post response @@ -131,7 +131,7 @@ describe('Complete CRUD Operations', () => { Authorization: 'Bearer jwt-token-abc', }), body: JSON.stringify({ text: updatedText }), - }) + }), ); // Mock READ updated posts response @@ -152,6 +152,11 @@ 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 @@ -163,13 +168,14 @@ describe('Complete CRUD Operations', () => { headers: expect.objectContaining({ Authorization: 'Bearer jwt-token-abc', }), - }) + }), ); // Mock DELETE user response fetchMock.mockResolvedValueOnce({ ok: true, status: 200, + json: async () => ({ user: 'Alice', message: 'User deleted' }), }); // DELETE: Remove the user @@ -181,7 +187,7 @@ describe('Complete CRUD Operations', () => { headers: expect.objectContaining({ Authorization: 'Bearer jwt-token-abc', }), - }) + }), ); }); @@ -208,7 +214,7 @@ describe('Complete CRUD Operations', () => { Authorization: 'Bearer mock-jwt-token', }), body: JSON.stringify({ text: newText }), - }) + }), ); }); @@ -218,6 +224,7 @@ describe('Complete CRUD Operations', () => { fetchMock.mockResolvedValueOnce({ ok: true, status: 200, + json: async () => ({ user: 'mock-user', message: 'User deleted' }), }); await deleteUser(); @@ -230,7 +237,7 @@ describe('Complete CRUD Operations', () => { headers: expect.objectContaining({ Authorization: 'Bearer mock-jwt-token', }), - }) + }), ); }); @@ -240,6 +247,7 @@ describe('Complete CRUD Operations', () => { fetchMock.mockResolvedValueOnce({ ok: true, status: 200, + json: async () => ({ id: 5, text: 'some text', message: 'Post deleted' }), }); await deletePost(5); @@ -252,7 +260,7 @@ describe('Complete CRUD Operations', () => { headers: expect.objectContaining({ Authorization: 'Bearer mock-jwt-token', }), - }) + }), ); }); @@ -275,7 +283,7 @@ describe('Complete CRUD Operations', () => { headers: expect.objectContaining({ Authorization: 'Bearer mock-jwt-token', }), - }) + }), ); expect(fetchMock).toHaveBeenCalledTimes(1); });