-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
414 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { portfoliosActions } from './portfoliosActions' | ||
import { Portfolio } from '@/@types/PortfoliosTypes' | ||
|
||
describe('portfoliosActions', () => { | ||
const initialState: Portfolio[] = [ | ||
{ id: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', name: 'Portfolio 1' }, | ||
{ id: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', name: 'Portfolio 2' }, | ||
{ id: 'b33c91c4-2661-462c-8cbd-a4501f629351', name: 'Portfolio 3' }, | ||
] | ||
|
||
test('should update the portfolio with the given payload', () => { | ||
const newState = portfoliosActions.update(initialState, { | ||
id: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', | ||
name: 'Portfolio Edited', | ||
}) | ||
|
||
expect(newState).toEqual([ | ||
{ id: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', name: 'Portfolio 1' }, | ||
{ id: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', name: 'Portfolio Edited' }, | ||
{ id: 'b33c91c4-2661-462c-8cbd-a4501f629351', name: 'Portfolio 3' }, | ||
]) | ||
}) | ||
|
||
test('should insert a new portfolio into the state', () => { | ||
const newState = portfoliosActions.insert(initialState, { | ||
name: 'Portfolio New', | ||
}) | ||
|
||
expect(newState).toEqual([ | ||
{ id: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', name: 'Portfolio 1' }, | ||
{ id: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', name: 'Portfolio 2' }, | ||
{ id: 'b33c91c4-2661-462c-8cbd-a4501f629351', name: 'Portfolio 3' }, | ||
{ id: expect.any(String), name: 'Portfolio New' }, | ||
]) | ||
}) | ||
|
||
test('should remove the specified portfolio from the state', () => { | ||
const newState = portfoliosActions.remove(initialState, { | ||
id: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', | ||
}) | ||
|
||
expect(newState).toEqual([ | ||
{ id: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', name: 'Portfolio 1' }, | ||
{ id: 'b33c91c4-2661-462c-8cbd-a4501f629351', name: 'Portfolio 3' }, | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import { describe, expect, test } from 'vitest' | ||
import { Ticker } from '@/@types/TickersTypes' | ||
import { tickersActions } from './tickersActions' | ||
|
||
describe('tickersActions', () => { | ||
const initialState: Ticker[] = [ | ||
{ ticker: 'AABB11', portfolioId: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', isHidden: false, quantity: 1 }, | ||
{ ticker: 'AABB11', portfolioId: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', isHidden: false, quantity: 1 }, | ||
{ ticker: 'AAXX11', portfolioId: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', isHidden: false, quantity: 1 }, | ||
] | ||
|
||
describe('insert', () => { | ||
test('should insert new tickers into the state', () => { | ||
const tickersList = ['AABB11', 'AAXX11'] | ||
const portfoliosList = [ | ||
'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', | ||
'bdcfe013-ae51-4f79-b8a1-791f745e9116', | ||
] | ||
|
||
const newState = tickersActions.insert(initialState, { | ||
tickersList, | ||
portfoliosList, | ||
}) | ||
|
||
expect(newState).toEqual([ | ||
{ ticker: 'AABB11', portfolioId: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', isHidden: false, quantity: 1 }, | ||
{ ticker: 'AABB11', portfolioId: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', isHidden: false, quantity: 1 }, | ||
{ ticker: 'AAXX11', portfolioId: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', isHidden: false, quantity: 1 }, | ||
{ ticker: 'AAXX11', portfolioId: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', isHidden: false, quantity: 1 }, | ||
]) | ||
}) | ||
}) | ||
|
||
describe('remove', () => { | ||
test('should remove the specified ticker from the state', () => { | ||
const ticker = 'AAXX11' | ||
const portfolioId = 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b' | ||
|
||
const newState = tickersActions.remove(initialState, { | ||
ticker, | ||
portfolioId, | ||
}) | ||
|
||
expect(newState).toEqual([ | ||
{ ticker: 'AABB11', portfolioId: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', isHidden: false, quantity: 1 }, | ||
{ ticker: 'AABB11', portfolioId: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', isHidden: false, quantity: 1 }, | ||
]) | ||
}) | ||
}) | ||
|
||
describe('update', () => { | ||
test('should update the specified ticker in the state', () => { | ||
const newState = tickersActions.update(initialState, { | ||
ticker: 'AABB11', | ||
portfolioId: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', | ||
isHidden: true, | ||
quantity: 5, | ||
}) | ||
|
||
expect(newState).toEqual([ | ||
{ ticker: 'AABB11', portfolioId: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', isHidden: false, quantity: 1 }, | ||
{ ticker: 'AABB11', portfolioId: 'bdcfe013-ae51-4f79-b8a1-791f745e9116', isHidden: true, quantity: 5 }, | ||
{ ticker: 'AAXX11', portfolioId: 'e5d46968-3a05-46d1-b5ec-a003c2a38a3b', isHidden: false, quantity: 1 }, | ||
]) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { afterEach, beforeEach, describe, expect, test } from 'vitest' | ||
import { getConfigAPI } from './config' | ||
|
||
describe('getConfigAPI', () => { | ||
beforeEach(() => { | ||
process.env.NEXT_PUBLIC_API_KEY = 'test-key' | ||
process.env.NEXT_PUBLIC_API_URL = 'https://api.example.com' | ||
process.env.NEXT_PUBLIC_API_CACHE = 'no-cache' | ||
process.env.NEXT_PUBLIC_API_REVALIDATE = '3600' | ||
}) | ||
|
||
afterEach(() => { | ||
delete process.env.NEXT_PUBLIC_API_KEY | ||
delete process.env.NEXT_PUBLIC_API_URL | ||
delete process.env.NEXT_PUBLIC_API_CACHE | ||
delete process.env.NEXT_PUBLIC_API_REVALIDATE | ||
}) | ||
|
||
test('should return config object with valid environment variables', () => { | ||
const expectedConfig = { | ||
key: 'test-key', | ||
url: 'https://api.example.com', | ||
cache: 'no-cache', | ||
revalidate: 3600, | ||
} | ||
|
||
const config = getConfigAPI() | ||
|
||
expect(config).toEqual(expectedConfig) | ||
}) | ||
|
||
test('should throw an error if NEXT_PUBLIC_API_KEY is not found', () => { | ||
delete process.env.NEXT_PUBLIC_API_KEY | ||
|
||
expect(getConfigAPI).toThrowError('NEXT_PUBLIC_API_KEY not found') | ||
}) | ||
|
||
test('should throw an error if NEXT_PUBLIC_API_URL is not found', () => { | ||
delete process.env.NEXT_PUBLIC_API_URL | ||
|
||
expect(getConfigAPI).toThrowError('NEXT_PUBLIC_API_URL not found') | ||
}) | ||
|
||
test('should return default values if NEXT_PUBLIC_API_CACHE is not found', () => { | ||
delete process.env.NEXT_PUBLIC_API_CACHE | ||
|
||
const expectedConfig = { | ||
key: 'test-key', | ||
url: 'https://api.example.com', | ||
cache: 'force-cache', | ||
revalidate: 3600, | ||
} | ||
|
||
const config = getConfigAPI() | ||
|
||
expect(config).toEqual(expectedConfig) | ||
}) | ||
|
||
test('should return default values if NEXT_PUBLIC_API_REVALIDATE is not found', () => { | ||
delete process.env.NEXT_PUBLIC_API_REVALIDATE | ||
|
||
const expectedConfig = { | ||
key: 'test-key', | ||
url: 'https://api.example.com', | ||
cache: 'no-cache', | ||
revalidate: 3600, | ||
} | ||
|
||
const config = getConfigAPI() | ||
|
||
expect(config).toEqual(expectedConfig) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { cn } from './cn' | ||
|
||
describe('cn', () => { | ||
test('should return string with merged values', () => { | ||
const result = cn('a', 'b', 'c') | ||
expect(result).toBe('a b c') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { type ClassValue, clsx } from 'clsx' | ||
import { twMerge } from 'tailwind-merge' | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { describe, test, expect } from 'vitest' | ||
import { toCurrency } from './currency' | ||
|
||
describe('toCurrency', () => { | ||
test('should return the correct currency format for a given number', () => { | ||
const number = 1234.56 | ||
const expected = 'R$ 1.234,56' | ||
|
||
const result = toCurrency(number) | ||
expect(result).toBe(expected) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { getLastDays } from './getLastDays' | ||
|
||
describe('getLastDays', () => { | ||
test('should return array with last 20 days', () => { | ||
const days = getLastDays() | ||
expect(days.length).toBe(20) | ||
}) | ||
|
||
test('should return array with custom days', () => { | ||
const days = getLastDays(10) | ||
expect(days.length).toBe(10) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import moment from 'moment' | ||
|
||
export function getLastDays(count = 20): string[] { | ||
const today = moment() | ||
const days = [] | ||
|
||
for (let i = 0; days.length < count; i++) { | ||
const currentDay = today.clone().subtract(i, 'days') | ||
|
||
if (currentDay.isoWeekday() !== 6 && currentDay.isoWeekday() !== 7) { | ||
const dayStr = currentDay.format('DD/MMM') | ||
days.push(dayStr) | ||
} | ||
} | ||
|
||
return days | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { getLastMonths } from './getLastMonths' | ||
|
||
describe('getLastMonths', () => { | ||
test('should return array with last 12 months', () => { | ||
const months = getLastMonths() | ||
expect(months.length).toBe(12) | ||
}) | ||
|
||
test('should return array with custom months', () => { | ||
const months = getLastMonths(10) | ||
expect(months.length).toBe(10) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import moment from 'moment' | ||
|
||
export function getLastMonths(count = 12): string[] { | ||
const today = moment() | ||
const months = [] | ||
|
||
for (let i = 0; i < count; i++) { | ||
const currentMonth = today.clone().subtract(i, 'months') | ||
const monthStr = currentMonth.format('MMM/YY') | ||
months.push(monthStr) | ||
} | ||
|
||
return months | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { mergeArrayOfObjects } from './mergeArrayOfObjects' | ||
|
||
describe('mergeArrayOfObjects', () => { | ||
test('should return object with merged values', () => { | ||
const arr = [{ a: 1 }, { b: 2 }, { c: 3 }, { a: 4 }] | ||
const result = mergeArrayOfObjects(arr) | ||
expect(result).toEqual({ a: 4, b: 2, c: 3 }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function mergeArrayOfObjects(arr: object[]): object { | ||
return arr.reduce((mergedObj, currentObj) => { | ||
return { ...mergedObj, ...currentObj } | ||
}, {}) | ||
} |
Oops, something went wrong.