Skip to content

Expand unit test coverage for the deal-stats data layer + B24 SDK smoke test #6

Description

@IgorShevchik

Context

PR #3 introduced the first unit tests (test/formatters.test.ts, test/helpers.test.ts, test/utils.test.ts) covering pure helpers. Several higher-value modules remain at 0% coverage, and the @bitrix24/b24jssdk 1→2 major bump is not exercised by any test. This issue tracks closing those gaps as a dedicated follow-up (kept out of PR #3 to avoid bloating a dependency-update PR and because it needs additional test harness setup).

Coverage gaps to close

  • app/composables/useDealStats/api.ts — the core CRM integration (currently untested):
    • paginated loading via b24.actions.v2.fetchList.make (mock the async generator with canned pages);
    • date-range boundary normalization (setHours(0,0,0,0) / 23:59:59.999);
    • the stageSemanticId === 'P' ? null : ... closedate nulling — this is the exact invariant getLatestSales's filter relies on, currently only assumed via hand-built fixtures;
    • revenue aggregation per currency, successfulDeals count, and uniqueCustomers dedup (contactId / companyId / 'empty' fallback).
  • app/composables/useDealStats/index.ts — orchestration: processCrmData / loadDeals, mock-vs-B24 branching, partial-stat callback merging, variation calc (current vs previous period), currency-list cleanup, and the SdkError error/toast path. Needs Nuxt auto-import mocking (useI18n, useToast, shallowRef, …) or @nuxt/test-utils.
  • app/composables/useDealStats/formatters.ts — formatDateRange and formatDateTimeShort are untested (add cases under the pinned TZ=UTC).
  • app/composables/useDealStats/helpers.ts — groupSalesByDate has two live @todo fix this markers; add edge cases (closedate before the earliest timestamp, duplicate/near timestamps, unsorted input) that pin current behavior before any fix.
  • app/composables/useDealStats/mocks.ts — smoke tests for generateMockStats / generateMockChart / generateMockSales (e.g. count, chart length matches dates).

B24 SDK smoke test (major bump 1→2)

No test currently exercises the SDK integration surface (useB24 init/set/get, initializeB24Frame, useB24Helper, LoadDataType, actions.v2.fetchList). Add at least a mocked smoke test that pins the expected shapes so a future SDK bump that changes them is caught by CI.

Test-harness prerequisites

  • vitest.config.ts currently has no setupFiles / path aliases / coverage config. Composable/orchestration tests will need Nuxt auto-import mocking (or @nuxt/test-utils) and possibly ~/#imports aliases.
  • Consider wiring vitest run --coverage and a coverage threshold into CI (.github/workflows/ci.yml) so gaps stay visible.

Acceptance

  • api.ts covered (pagination, date bounds, closedate nulling, aggregation, dedup)
  • index.ts orchestration covered (mock + B24 branches, error path)
  • formatDateRange / formatDateTimeShort covered (TZ-pinned)
  • groupSalesByDate edge cases covered
  • mocks.ts smoke-tested
  • B24 SDK smoke test in place
  • coverage reporting wired into CI

Follow-up to PR #3.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions