Skip to content

Commit faf5ba8

Browse files
committed
Use an in-memory repository to save shortened url
1 parent 6e901f0 commit faf5ba8

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

webapp/app/api/url-shortener/route.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import { NextRequest, NextResponse } from 'next/server';
44
export async function POST(request: NextRequest) {
55
try {
66
const { url } = await request.json();
7-
8-
console.log('Sending request body:', request.body); // ✅ Debugging
9-
107
if (!url || typeof url !== 'string') {
118
throw new Error(`Invalid URL format ${url}`);
129
}
@@ -37,9 +34,7 @@ async function shortenUrl(url: string): Promise<string> {
3734
throw new Error(errorResponse.error || 'Failed to shorten URL');
3835
}
3936

40-
const data = await response.json(); // Expected { shortenedUrl: "https://short.ly/abc123" }
41-
console.log('URL shortened successfully:', data);
42-
37+
const data = await response.json();
4338
return data;
4439
} catch (error) {
4540
console.error('Error shortening URL:', error);

webapp/components/url-shortener/hooks/useURLShortener.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useState } from 'react';
22
import { shortenURL } from '../services/url-shorten-service';
3-
import * as console from 'node:console';
43

54
export const useURLShortener = () => {
65
const shorten = async () => {

webapp/components/url-shortener/services/url-shorten-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export const shortenURL = async (longUrl: string): Promise<string> => {
1313
}
1414

1515
const data = await response.json();
16-
return data.shortenedUrl.shortenedUrl;
16+
return data.shortenedUrl;
1717
};

webapp/components/url-shortener/ui/URLShortener.test.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
22
import { describe, it, expect } from '@jest/globals';
33
import { URLShortener } from './URLShortener';
4-
import React, { act } from 'react';
4+
import React from 'react';
55

66
global.fetch = jest.fn();
77

@@ -26,7 +26,7 @@ describe('URLShortenerV2', () => {
2626
const shortenedUrl = 'https://short.ly/abc123';
2727
global.fetch = jest.fn().mockResolvedValue({
2828
ok: true,
29-
json: async () => ({ shortenedUrl }), // API response in JSON
29+
json: async () => ({ shortenedUrl: shortenedUrl }), // API response in JSON
3030
});
3131

3232
render(<URLShortener />);
@@ -51,7 +51,6 @@ describe('URLShortenerV2', () => {
5151
const shortenedUrlTextBox = screen.getByRole('textbox', {
5252
name: /shortened url/i,
5353
});
54-
//expect(shortenedUrlTextBox).toHaveValue('should-be-a-shortened-url');
5554
expect(shortenedUrlTextBox).toHaveValue(shortenedUrl);
5655
expect(
5756
screen.queryByRole('button', { name: /shorten url/i })

0 commit comments

Comments
 (0)