/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals' // Mock all required modules jest.mock('@actions/core') jest.mock('@actions/github', () => ({ context: { payload: { repository: { name: 'test-repo' } }, repo: { owner: 'test-owner' }, }, getOctokit: jest.fn(), })) // Mock the main modules we'll need const mockGetFirstBlocks = jest.fn() jest.mock('../src/utils/slack/blocks.js', () => ({ getFirstBlocks: mockGetFirstBlocks, getLastBlocks: jest.fn(() => []), getPullBlocks: jest.fn(() => Promise.resolve([])), })) const mockSlackPostMessage = jest.fn() jest.mock('../src/utils/slack/client.js', () => ({ SlackClient: jest.fn(() => ({ enforceAppNamePattern: jest.fn(), postMessage: mockSlackPostMessage, })), })) jest.mock('../src/utils/github/client.js', () => { const mockGetOrg = jest.fn() mockGetOrg.mockImplementation(() => Promise.resolve({ name: 'test-org' })) return { GitHubClient: jest.fn(() => ({ getOrg: mockGetOrg, getPulls: jest.fn(() => Promise.resolve([])), getRepositories: jest.fn(() => Promise.resolve([])), })), } }) jest.mock('../src/utils/test-data.js') jest.mock('../src/input-parser.js', () => ({ parseInputs: jest.fn(() => ({ githubConfig: { options: {}, tokens: ['fake-token1', 'fake-token2'], }, repositoryFilter: [], slackConfig: { channels: [], token: 'fake-token' }, withArchived: false, withDrafts: false, withPublic: false, withTestData: false, withUserMentions: false, })), })) describe('Organization links in Slack notifications', () => { beforeEach(() => { jest.resetAllMocks() jest.spyOn(console, 'log').mockImplementation(jest.fn()) jest.spyOn(console, 'error').mockImplementation(jest.fn()) }) afterEach(() => { jest.restoreAllMocks() }) it('passes org names to getFirstBlocks from results array, not dedupedPulls', () => { // We test this logic: // const orgs = [...new Set(results.map((result) => result.org))] // blocks = [...getFirstBlocks(orgs, header, text), ...blocks] jest.isolateModules(() => { // Create spies to verify the behavior const orgSpy = jest.fn() mockGetFirstBlocks.mockImplementation((orgs) => { orgSpy(orgs) return [] }) // This test doesn't actually run the code in app.ts, but verifies // that with the fix in place, orgs would be obtained from results // rather than dedupedPulls when there are no PRs const results = [{ org: 'org1' }, { org: 'org2' }] const dedupedPulls: any[] = [] // Simulate the fixed code behavior const orgs = [...new Set(results.map((result) => result.org))] expect(orgs).toEqual(['org1', 'org2']) // Verify that the old behavior would result in empty orgs const oldOrgs = [...new Set(dedupedPulls.map((pull) => (pull as { org: string }).org))] expect(oldOrgs).toEqual([]) }) }) })