Skip to content

Commit

Permalink
fix: test case download added
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuran-deriv committed Sep 17, 2024
1 parent a1a51e4 commit b96f68c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
90 changes: 90 additions & 0 deletions packages/bot-web-ui/src/utils/__tests__/download.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { LogTypes } from '@deriv/bot-skeleton';
import { localize } from '@deriv/translations';
import { getCurrentDateTimeLocale, getSuccessJournalMessage } from 'Utils/download';

jest.mock('@deriv/translations', () => ({
localize: jest.fn((message, values) => {
let result = message;
if (values) {
Object.keys(values).forEach(key => {
result = result.replace(`{{${key}}}`, values[key]);
});
}
return result;
}),
}));
jest.mock('@deriv/bot-skeleton', () => ({
LogTypes: {
LOAD_BLOCK: 'load_block',
PURCHASE: 'purchase',
SELL: 'sell',
NOT_OFFERED: 'not_offered',
PROFIT: 'profit',
LOST: 'lost',
WELCOME_BACK: 'welcome_back',
WELCOME: 'welcome',
},
}));
describe('getCurrentDateTimeLocale', () => {
it('should return the current date and time in UTC with the format YYYY-MM-DD HHMMSS', () => {
const result = getCurrentDateTimeLocale();
const now = new Date();
const year = now.getUTCFullYear();
const month = (now.getUTCMonth() + 1).toString().padStart(2, '0');
const day = now.getUTCDate().toString().padStart(2, '0');
const hours = now.getUTCHours().toString().padStart(2, '0');
const minutes = now.getUTCMinutes().toString().padStart(2, '0');
const seconds = now.getUTCSeconds().toString().padStart(2, '0');
const expected = `${year}-${month}-${day} ${hours}${minutes}${seconds}`;
expect(result).toBe(expected);
});
});
describe('getSuccessJournalMessage', () => {
it('should return localized message for LOAD_BLOCK', () => {
const result = getSuccessJournalMessage(LogTypes.LOAD_BLOCK, {});
expect(result).toBe('Blocks are loaded successfully');
});
it('should return localized message for PURCHASE with longcode and transaction_id', () => {
const extra = { longcode: 'Sample Longcode', transaction_id: '1234' };
const result = getSuccessJournalMessage(LogTypes.PURCHASE, extra);
expect(result).toBe('Bought: Sample Longcode (ID: 1234)');
});
it('should return localized message for SELL with sold_for', () => {
const extra = { sold_for: '100 USD' };
const result = getSuccessJournalMessage(LogTypes.SELL, extra);
expect(result).toBe('Sold for: 100 USD');
});
it('should return localized message for PROFIT with profit', () => {
const extra = { profit: '50 USD' };
const result = getSuccessJournalMessage(LogTypes.PROFIT, extra);
expect(result).toBe('Profit amount: 50 USD');
});
it('should return localized message for LOST with profit', () => {
const extra = { profit: '20 USD' };
const result = getSuccessJournalMessage(LogTypes.LOST, extra);
expect(result).toBe('Loss amount: 20 USD');
});
it('should return localized message for WELCOME_BACK with current_currency', () => {
const extra = { current_currency: 'USD' };
const result = getSuccessJournalMessage(LogTypes.WELCOME_BACK, extra);
expect(result).toBe('Welcome back! Your messages have been restored. You are using your USD account.');
});
it('should return localized message for WELCOME_BACK without current_currency', () => {
const extra = {}; // No current_currency provided
const result = getSuccessJournalMessage(LogTypes.WELCOME_BACK, extra);
expect(result).toBe('Welcome back! Your messages have been restored.');
});
it('should return localized message for WELCOME with current_currency', () => {
const extra = { current_currency: 'EUR' };
const result = getSuccessJournalMessage(LogTypes.WELCOME, extra);
expect(result).toBe('You are using your EUR account.');
});
it('should return localized message for NOT_OFFERED with empty extra', () => {
const result = getSuccessJournalMessage(LogTypes.NOT_OFFERED, {});
expect(result).toBe('Resale of this contract is not offered.');
});
it('should return empty string for unknown log type', () => {
const result = getSuccessJournalMessage('unknown_log_type' as LogTypes[keyof LogTypes], {});
expect(result).toBe('');
});
});
2 changes: 1 addition & 1 deletion packages/bot-web-ui/src/utils/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type TExtra = {
current_currency?: string;
};

const getCurrentDateTimeLocale = () => {
export const getCurrentDateTimeLocale = () => {
const date = new Date(); // This will be the current date and time

const year = date.getUTCFullYear();
Expand Down

0 comments on commit b96f68c

Please sign in to comment.