<commit_before>import { APIRefState } from '../../src/lib/api'
import { getRefStatusSummary } from '../../src/ui/branches/pull-request-status'
import { IRefStatus } from '../../src/lib/stores/commit-status-store'

const failure: APIRefState = 'failure'
const pending: APIRefState = 'pending'
const success: APIRefState = 'success'

describe('pull request status', () => {
  it('uses the state when no statuses found', () => {
    const status: IRefStatus = {
      state: success,
      totalCount: 0,
      statuses: {
        total_count: 0,
        state: pending,
        statuses: [],
      },
      checkRuns: {
        total_count: 0,
        check_runs: [],
      },
    }
    expect(getRefStatusSummary(status)).toBe('Commit status: success')
  })

  it('changes the failure message to something more friendly', () => {
    const status: IRefStatus = {
      state: failure,
      totalCount: 0,
      statuses: {
        total_count: 0,
        state: pending,
        statuses: [],
      },
      checkRuns: {
        total_count: 0,
        check_runs: [],
      },
    }
    expect(getRefStatusSummary(status)).toBe('Commit status: failed')
  })

  it('reads the statuses when they are populated', () => {
    const status: IRefStatus = {
      state: success,
      totalCount: 2,
      statuses: {
        total_count: 2,
        state: success,
        statuses: [
          {
            id: 1,
            state: success,
            description: 'first',
            target_url: '',
            context: '2',
          },
          {
            id: 2,
            state: success,
            description: 'second',
            target_url: '',
            context: '2',
          },
        ],
      },
      checkRuns: {
        total_count: 0,
        check_runs: [],
      },
    }
    expect(getRefStatusSummary(status)).toBe('2/2 checks OK')
  })

  it('a successful status shows the description', () => {
    const status: IRefStatus = {
      state: success,
      totalCount: 1,
      statuses: {
        total_count: 1,
        state: success,
        statuses: [
          {
            id: 1,
            state: success,
            description: 'The Travis CI build passed',
            target_url: '',
            context: '1',
          },
        ],
      },
      checkRuns: {
        total_count: 0,
        check_runs: [],
      },
    }

    expect(getRefStatusSummary(status)).toBe(
      'Success: The Travis CI build passed'
    )
  })

  it('an error status shows the description', () => {
    const status: IRefStatus = {
      state: failure,
      totalCount: 1,
      statuses: {
        total_count: 1,
        state: failure,
        statuses: [
          {
            id: 1,
            state: failure,
            description: 'The Travis CI build failed',
            target_url: '',
            context: '1',
          },
        ],
      },
      checkRuns: {
        total_count: 0,
        check_runs: [],
      },
    }

    expect(getRefStatusSummary(status)).toBe(
      'Failure: The Travis CI build failed'
    )
  })

  it('only counts the successful statuses', () => {
    const status: IRefStatus = {
      state: success,
      totalCount: 3,
      statuses: {
        total_count: 3,
        state: success,
        statuses: [
          {
            id: 1,
            state: success,
            description: 'first',
            target_url: '',
            context: '1',
          },
          {
            id: 2,
            state: pending,
            description: 'second',
            target_url: '',
            context: '2',
          },
          {
            id: 2,
            state: pending,
            description: 'third',
            target_url: '',
            context: '3',
          },
        ],
      },
      checkRuns: {
        total_count: 0,
        check_runs: [],
      },
    }

    expect(getRefStatusSummary(status)).toBe('1/3 checks OK')
  })
})<commit_msg>Update tests with new types<commit_after>import { APIRefState } from '../../src/lib/api'
import { getRefStatusSummary } from '../../src/ui/branches/pull-request-status'
import { ICombinedRefStatus } from '../../src/lib/stores/commit-status-store'

const failure: APIRefState = 'failure'
const pending: APIRefState = 'pending'
const success: APIRefState = 'success'

describe('pull request status', () => {
  it('uses the state when no statuses found', () => {
    const status: ICombinedRefStatus = {
      state: success,
      checks: [],
    }
    expect(getRefStatusSummary(status)).toBe('Commit status: success')
  })

  it('changes the failure message to something more friendly', () => {
    const status: ICombinedRefStatus = {
      state: failure,
      checks: [],
    }
    expect(getRefStatusSummary(status)).toBe('Commit status: failed')
  })

  it('reads the statuses when they are populated', () => {
    const status: ICombinedRefStatus = {
      state: success,
      checks: [
        {
          state: success,
          name: '1',
          description: 'first',
        },
        {
          state: success,
          name: '2',
          description: 'second',
        },
      ],
    }
    expect(getRefStatusSummary(status)).toBe('2/2 checks OK')
  })

  it('a successful status shows the description', () => {
    const status: ICombinedRefStatus = {
      state: success,
      checks: [
        {
          state: success,
          name: 'travis',
          description: 'The Travis CI build passed',
        },
      ],
    }

    expect(getRefStatusSummary(status)).toBe(
      'travis: The Travis CI build passed'
    )
  })

  it('an error status shows the description', () => {
    const status: ICombinedRefStatus = {
      state: failure,
      checks: [
        {
          state: failure,
          name: 'travis',
          description: 'The Travis CI build failed',
        },
      ],
    }

    expect(getRefStatusSummary(status)).toBe(
      'travis: The Travis CI build failed'
    )
  })

  it('only counts the successful statuses', () => {
    const status: ICombinedRefStatus = {
      state: success,
      checks: [
        {
          state: success,
          description: 'first',
          name: '1',
        },
        {
          state: pending,
          description: 'second',
          name: '2',
        },
        {
          state: pending,
          description: 'third',
          name: '3',
        },
      ],
    }

    expect(getRefStatusSummary(status)).toBe('1/3 checks OK')
  })
})
{'fraction_non_alphanumeric': 0.13083538083538085, 'fraction_numerical': 0.00691031941031941, 'mean_word_length': 1.6703567035670357, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '514428', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1867, 'n_words': 447}