Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Jan 10, 2025
1 parent d954d46 commit 4e0d2ab
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/tradingView/dydxfeed/__test__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { ResolutionString } from 'public/tradingview/charting_library';
import { describe, expect, it } from 'vitest';

import { timeUnits } from '@/constants/time';

import { getBarTime } from '../utils';

describe('getBarTime', () => {
it('should return the correct value when times start at 0', () => {
const beginningOfChart = getBarTime(0, 0, '1' as ResolutionString);
expect(beginningOfChart).toBe(0);

const middleOfChart = getBarTime(0, 10001, '1' as ResolutionString);
expect(middleOfChart).toBe(10);
const middleOfChart = getBarTime(0, timeUnits.minute * 10 + 1, '1' as ResolutionString);
expect(middleOfChart).toBe(600);
});

it('should return the correct value when times dont start at 0', () => {
// Intervals here look like 100, 1100, ... 9100, 10100, .etc
// Should resolve to 9100ms bucket which is 9s
const nonZeroStart = getBarTime(100, 10001, '1' as ResolutionString);
expect(nonZeroStart).toBe(9);
const nonZeroStart = getBarTime(100, timeUnits.minute * 10 + 1, '1' as ResolutionString);
expect(nonZeroStart).toBe(540);
});

it('should return correct value with real timestamps', () => {
Expand Down

0 comments on commit 4e0d2ab

Please sign in to comment.