Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.8 kB
0
Indexable
Never
import { activeRecord } from './your-module'; // Replace 'your-module' with the actual path to your module

// Mock Date to ensure consistent results
jest.spyOn(global, 'Date').mockImplementation(() =>
  new Date('2024-01-01T12:00:00.000Z') // Replace with your desired mock date
);

describe('activeRecord function', () => {
  afterEach(() => {
    jest.restoreAllMocks();
  });

  it('returns false if displayOrder is missing', () => {
    const record = { effDate: '2024-01-01', expDate: '2024-12-31' };
    expect(activeRecord(record)).toBe(false);
  });

  it('returns false if displayOrder is less than 1', () => {
    const record = { displayOrder: 0, effDate: '2024-01-01', expDate: '2024-12-31' };
    expect(activeRecord(record)).toBe(false);
  });

  it('returns false if effDate or expDate is missing', () => {
    const record = { displayOrder: 5, expDate: '2024-12-31' };
    expect(activeRecord(record)).toBe(false);
  });

  it('returns false if currentDate is not between effDate and expDate', () => {
    const record = { displayOrder: 5, effDate: '2025-01-01', expDate: '2025-12-31' };
    expect(activeRecord(record)).toBe(false);
  });

  it('returns true if currentDate is equal to effDate and displayOrder is valid', () => {
    const record = { displayOrder: 5, effDate: '2024-01-01', expDate: '2024-12-31' };
    expect(activeRecord(record)).toBe(true);
  });

  it('returns true if currentDate is equal to expDate and displayOrder is valid', () => {
    const record = { displayOrder: 5, effDate: '2023-01-01', expDate: '2024-01-01' };
    expect(activeRecord(record)).toBe(true);
  });

  it('returns true if currentDate is equal to both effDate and expDate and displayOrder is valid', () => {
    const record = { displayOrder: 5, effDate: '2024-01-01', expDate: '2024-01-01' };
    expect(activeRecord(record)).toBe(true);
  });

  it('returns false if currentDate is equal to both effDate and expDate but displayOrder is invalid', () => {
    const record = { displayOrder: 0, effDate: '2024-01-01', expDate: '2024-01-01' };
    expect(activeRecord(record)).toBe(false);
  });

  it('returns false if currentDate is equal to effDate but displayOrder is invalid', () => {
    const record = { displayOrder: 0, effDate: '2024-01-01', expDate: '2024-12-31' };
    expect(activeRecord(record)).toBe(false);
  });

  it('returns false if currentDate is equal to expDate but displayOrder is invalid', () => {
    const record = { displayOrder: 0, effDate: '2024-01-01', expDate: '2024-01-01' };
    expect(activeRecord(record)).toBe(false);
  });

  it('returns false if effDate is equal to expDate but displayOrder is invalid', () => {
    const record = { displayOrder: 0, effDate: '2024-01-01', expDate: '2024-01-01' };
    expect(activeRecord(record)).toBe(false);
  });
});
Leave a Comment