From 9b3cb64acb9c0082bc499bb16c77806f310c0d3f Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Wed, 18 Mar 2026 11:09:50 +0100 Subject: [PATCH 1/2] task-1 complete --- task-1/cocktail.js | 103 +++++++++++- task-1/output/margarita.md | 136 ++++++++++++++++ task-1/output/martini.md | 317 +++++++++++++++++++++++++++++++++++++ task-1/output/mojito.md | 96 +++++++++++ 4 files changed, 646 insertions(+), 6 deletions(-) create mode 100644 task-1/output/margarita.md create mode 100644 task-1/output/martini.md create mode 100644 task-1/output/mojito.md diff --git a/task-1/cocktail.js b/task-1/cocktail.js index 6fd5a62..27b3e54 100644 --- a/task-1/cocktail.js +++ b/task-1/cocktail.js @@ -1,12 +1,89 @@ // API documentation: https://www.thecocktaildb.com/api.php import path from 'path'; +import fs from 'fs/promises'; const BASE_URL = 'https://www.thecocktaildb.com/api/json/v1/1'; -// Add helper functions as needed here +function getIngredients(drink) { + const lines = []; + for (let i = 1; i <= 15; i++) { + const ingredientKey = 'strIngredient' + i; + const measureKey = 'strMeasure' + i; -export async function main() { + const ingredientRaw = drink[ingredientKey]; + const measureRaw = drink[measureKey]; + + let ingredient = ''; + let measure = ''; + + if (ingredientRaw) { + ingredient = ingredientRaw.trim(); + } + if (measureRaw) { + measure = measureRaw.trim(); + } + if (ingredient !== '') { + let line = '- '; + if (measure !== '') { + line = line + measure + ' '; + } + line = line + ingredient; + lines.push(line); + } + } + return lines.join('\n'); +} + + function formatAlcoholicDrink(drink) { + if (drink.strAlcoholic === 'Alcoholic') { + return 'Yes'; + } + return 'No'; + } + + function formatDrinkMarkdown(drink) { + const lines = []; + + lines.push(`## ${drink.strDrink}`); + lines.push(''); + lines.push(`![${drink.strDrink}](${drink.strDrinkThumb}/medium)`); + lines.push(''); + lines.push(`**Category**: ${drink.strCategory}`); + lines.push(''); + lines.push(`**Alcoholic**: ${formatAlcoholicDrink(drink)}`); + lines.push(''); + lines.push(`### Ingredients`); + lines.push(''); + lines.push(getIngredients(drink)); + lines.push(''); + lines.push(`### Instructions`); + lines.push(''); + lines.push(drink.strInstructions); + lines.push(''); + lines.push(`Served in: ${drink.strGlass}`); + + return lines.join('\n'); + } + + function formatMarkdown(drinks) { + const lines = []; + lines.push('# Cocktail Recipes'); + lines.push(''); + + for ( let i = 0; i < drinks.length; i++) { + lines.push(formatDrinkMarkdown(drinks[i])); + + if (i < drinks.length - 1) { + lines.push('---'); + lines.push(''); + } + } + + return lines.join('\n'); + } + +async function main() { if (process.argv.length < 3) { console.error('Please provide a cocktail name as a command line argument.'); return; @@ -19,11 +96,25 @@ 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('Failed to fetch cocktail data'); + } + + const data = await response.json(); + + if (!data.drinks) { + throw new Error('No drinks found'); + } + + const markdownContent = formatMarkdown(data.drinks); + + await fs.writeFile(outPath, markdownContent, 'utf-8'); + + console.log('Saved to: ' + outPath); } catch (error) { - // 4. Handle errors + console.error('Error:', error.message); } } diff --git a/task-1/output/margarita.md b/task-1/output/margarita.md new file mode 100644 index 0000000..d3d1eb6 --- /dev/null +++ b/task-1/output/margarita.md @@ -0,0 +1,136 @@ +# 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. + +Served 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. + +Served 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. + +Served 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. + +Served 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. + +Served 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. + +Served in: Collins glass \ No newline at end of file diff --git a/task-1/output/martini.md b/task-1/output/martini.md new file mode 100644 index 0000000..1edcbbb --- /dev/null +++ b/task-1/output/martini.md @@ -0,0 +1,317 @@ +# Cocktail Recipes + +## Martini + +![Martini](https://www.thecocktaildb.com/images/media/drink/71t8581504353095.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1 2/3 oz Gin +- 1/3 oz Dry Vermouth +- 1 Olive + +### 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. + +Served 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 oz Gin +- 1/3 oz Dry Vermouth +- 1 Olive + +### 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. + +Served in: Cocktail glass +--- + +## Kiwi Martini + +![Kiwi Martini](https://www.thecocktaildb.com/images/media/drink/bmxmyq1630407098.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1/2 Kiwi +- 1 tsp Sugar Syrup +- 1 1/2 oz Vodka +- Garnish with Kiwi + +### 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. + +Served 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 oz Vodka +- 3/4 oz Dry Vermouth +- 1 Olive + +### Instructions + +Shake the vodka and vermouth together with a number of ice cubes, strain into a cocktail glass, add the olive and serve. + +Served in: Cocktail glass +--- + +## Dirty Martini + +![Dirty Martini](https://www.thecocktaildb.com/images/media/drink/vcyvpq1485083300.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 70ml/2fl oz Vodka +- 1 tbsp Dry Vermouth +- 2 tbsp Olive Brine +- 1 wedge Lemon +- 1 Olive + +### 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. + +Served in: Cocktail glass +--- + +## Abbey Martini + +![Abbey Martini](https://www.thecocktaildb.com/images/media/drink/2mcozt1504817403.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 2 shots Gin +- 1 shot Sweet Vermouth +- 1 shot Orange Juice +- 3 dashes Angostura Bitters + +### Instructions + +Put all ingredients into a shaker and mix, then strain contents into a chilled cocktail glass. + +Served in: Cocktail glass +--- + +## French Martini + +![French Martini](https://www.thecocktaildb.com/images/media/drink/clth721504373134.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 4.5 cl Vodka +- 1.5 cl Raspberry Liqueur +- 1.5 cl pineapple 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. + +Served in: Cocktail glass +--- + +## Bellini Martini + +![Bellini Martini](https://www.thecocktaildb.com/images/media/drink/3h9wv51504389379.jpg/medium) + +**Category**: Ordinary Drink + +**Alcoholic**: Yes + +### Ingredients + +- 8 cubes Ice +- 3 oz Vodka +- 1.5 oz Peach nectar +- 1.5 oz Peach schnapps +- 1 Lemon peel + +### Instructions + +Add ice cubes to shaker. +Add vodka. +Add peach schnapps. +Add peach nectar. +Shake. +Strain into glass. +Add lemon twist peel. + +Served in: Cocktail glass +--- + +## Espresso Martini + +![Espresso Martini](https://www.thecocktaildb.com/images/media/drink/n0sx531504372951.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 5 cl Vodka +- 1 cl Kahlua +- 1 dash Sugar syrup + +### Instructions + +Pour ingredients into shaker filled with ice, shake vigorously, and strain into chilled martini glass + +Served in: Cocktail glass +--- + +## Pornstar Martini + +![Pornstar Martini](https://www.thecocktaildb.com/images/media/drink/xjhjdf1630406071.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 3 cl Vodka +- 3 cl Passoa +- 1 cl Passion fruit juice +- 1 cl Lime +- 1 shot Prosecco + +### 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. + +Served in: Cocktail glass +--- + +## Cosmopolitan Martini + +![Cosmopolitan Martini](https://www.thecocktaildb.com/images/media/drink/upxxpq1439907580.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1/2 oz Cointreau +- 1 oz Vodka +- Juice of 1/2 Lime +- 1 splash Cranberry juice + +### Instructions + +Pour all ingredients in mixing glass half filled with ice, shake and strain into chilled Martini glass. + +Served 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 ml Gin +- 30 ml Chocolate liqueur +- 15 ml Amaretto +- Garnish Chocolate Sauce +- Grated Salted 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! + +Served 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 shot Vodka +- 1/2 shot Sugar Syrup +- Full Glass Passion fruit juice + +### Instructions + +Pour all ingredients into a glass and stir. Garnish with half a passion fruit piece. + +Served 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 cl Vermouth +- 16 cl Apple juice + +### Instructions + +Serve without ice. At least the juice shold have room temperature. + +Served in: Collins Glass \ No newline at end of file diff --git a/task-1/output/mojito.md b/task-1/output/mojito.md new file mode 100644 index 0000000..1f29b38 --- /dev/null +++ b/task-1/output/mojito.md @@ -0,0 +1,96 @@ +# Cocktail Recipes + +## Mojito + +![Mojito](https://www.thecocktaildb.com/images/media/drink/metwgh1606770327.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 2-3 oz Light rum +- Juice of 1 Lime +- 2 tsp Sugar +- 2-4 Mint +- Soda water + +### Instructions + +Muddle mint leaves with sugar and lime juice. Add a splash of soda water and fill the glass with cracked ice. Pour the rum and top with soda water. Garnish and serve with straw. + +Served in: Highball glass +--- + +## Mojito Extra + +![Mojito Extra](https://www.thecocktaildb.com/images/media/drink/vwxrsw1478251483.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 1/2 handful Mint +- 3 cl Lemon juice +- 1/8 L Jamaican Dark rum +- 1/8 L Club soda +- 8 drops Angostura bitters + +### Instructions + +Put mint with lemon juice in a glas, mash the mint with a spoon, ice, rum & fill up with club soda. Top it with Angostura. + +Served in: Collins glass +--- + +## Mango Mojito + +![Mango Mojito](https://www.thecocktaildb.com/images/media/drink/wfqmgm1630406820.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 3 Lime +- 1 Fresh Mango +- Sprig Mint +- 200 ml White Rum +- cubes Ice +- Top Soda Water +- Garnish with Mango + +### Instructions + +Squeeze the juice from 1½ limes and blend with the mango to give a smooth purée. +Cut the rest of the limes into quarters, and then cut each wedge in half again. Put 2 pieces of lime in a highball glass for each person and add 1 teaspoon of caster sugar and 5-6 mint leaves to each glass. Squish everything together with a muddler or the end of a rolling pin to release all the flavours from the lime and mint. +Divide the mango purée between the glasses and add 30ml white rum and a handful of crushed ice to each one, stirring well to mix everything together. Top up with soda water to serve and garnish with extra mint, if you like. + +Served in: Jar +--- + +## Blueberry Mojito + +![Blueberry Mojito](https://www.thecocktaildb.com/images/media/drink/07iep51598719977.jpg/medium) + +**Category**: Cocktail + +**Alcoholic**: Yes + +### Ingredients + +- 2 shots Dark Rum +- 1 shot Lime Juice +- Dash Sugar +- Whole Blueberries +- Top Lemon-lime soda + +### Instructions + +Muddle the blueberries with the other ingredients and serve in a highball glass. Garnish with mint and a half slice of lime. + +Served in: Highball glass \ No newline at end of file From ed0c3a7f2e3dabe1575beb7b767ce075263057a2 Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Wed, 18 Mar 2026 23:33:17 +0100 Subject: [PATCH 2/2] task-2 complete --- task-2/post-cli/package-lock.json | 3 +- task-2/post-cli/src/services.js | 84 ++++++++++++++++++++++--- task-2/post-cli/tests/test-crud.test.js | 8 ++- task-2/post-cli/tests/test-post.test.js | 6 +- 4 files changed, 86 insertions(+), 15 deletions(-) diff --git a/task-2/post-cli/package-lock.json b/task-2/post-cli/package-lock.json index 8c03ed4..776be27 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", diff --git a/task-2/post-cli/src/services.js b/task-2/post-cli/src/services.js index 2601f57..3575234 100644 --- a/task-2/post-cli/src/services.js +++ b/task-2/post-cli/src/services.js @@ -1,5 +1,6 @@ // 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 = 'https://postcentral.hyf.dev'; +const BASE_URL = 'https://postcentral.hyf.dev'; // ============================================================================ // AUTH TOKEN - Stored after login/register, sent with every request @@ -53,7 +54,17 @@ const getHello = async () => { * Response: { user: string } */ const getMe = async () => { - // TODO + const response = await fetch(`${BASE_URL}/users/me`, { + headers: { + Authorization: `Bearer ${getToken()}`, + }, + }); + if (!response.ok) { + throw new Error( + `Failed to get user info: HTTP ${response.status} ${response.statusText}` + ); + } + return await response.json(); }; // ============================================================================ @@ -89,7 +100,17 @@ 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: HTTP ${response.status} ${response.statusText}` + ); + } + return await response.json(); }; // ============================================================================ @@ -103,7 +124,17 @@ 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 +143,15 @@ const createPost = async (text) => { * Response: Array of { id, text, user } */ const getPosts = async () => { - // TODO + const response = await fetch(`${BASE_URL}/posts/me`, { + headers: { Authorization: `Bearer ${getToken()}` }, + }); + if (!response.ok) { + throw new Error( + `Failed to get posts: HTTP ${response.status} ${response.statusText}` + ); + } + return await response.json(); }; /** @@ -122,16 +161,36 @@ 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(); }; + /** * Delete current user * Method: DELETE | Endpoint: /users/me | Auth: Yes * 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 +199,16 @@ 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..fa269fa 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,12 +171,13 @@ describe('Complete CRUD Operations', () => { fetchMock.mockResolvedValueOnce({ ok: true, status: 200, + json: async () => ({ user: 'Alice', message: 'User deleted' }), }); // DELETE: Remove the user await deleteUser(); expect(fetchMock).toHaveBeenLastCalledWith( - 'http://localhost:3000/users/me', + 'https://postcentral.hyf.dev/users/me', expect.objectContaining({ method: 'DELETE', headers: expect.objectContaining({ @@ -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 diff --git a/task-2/post-cli/tests/test-post.test.js b/task-2/post-cli/tests/test-post.test.js index 0431c68..58f1766 100644 --- a/task-2/post-cli/tests/test-post.test.js +++ b/task-2/post-cli/tests/test-post.test.js @@ -46,7 +46,7 @@ describe('POST Functions', () => { // Verify fetch was called with correct parameters expect(fetchMock).toHaveBeenCalledWith( - 'http://localhost:3000/users/register', + 'https://postcentral.hyf.dev/users/register', { method: 'POST', headers: { @@ -119,7 +119,7 @@ describe('POST Functions', () => { // Verify fetch was called with correct parameters expect(fetchMock).toHaveBeenCalledWith( - 'http://localhost:3000/users/login', + 'https://postcentral.hyf.dev/users/login', { method: 'POST', headers: { @@ -174,7 +174,7 @@ describe('POST Functions', () => { await createPost(postText); // Verify fetch was called with correct parameters including auth header - expect(fetchMock).toHaveBeenCalledWith('http://localhost:3000/posts', { + expect(fetchMock).toHaveBeenCalledWith('https://postcentral.hyf.dev/posts', { method: 'POST', headers: { 'Content-Type': 'application/json',