|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +const checkForReproducer = require('../checkForReproducer'); |
| 13 | + |
| 14 | +const ISSUE_AUTHOR = 'issue-author'; |
| 15 | + |
| 16 | +function buildGithub(body) { |
| 17 | + return { |
| 18 | + rest: { |
| 19 | + issues: { |
| 20 | + get: jest.fn().mockResolvedValue({ |
| 21 | + data: { |
| 22 | + user: {login: ISSUE_AUTHOR}, |
| 23 | + created_at: '2026-10-01T00:00:00Z', |
| 24 | + body, |
| 25 | + }, |
| 26 | + }), |
| 27 | + listComments: jest.fn().mockResolvedValue({data: []}), |
| 28 | + listEventsForTimeline: jest.fn().mockResolvedValue({data: []}), |
| 29 | + removeLabel: jest.fn().mockResolvedValue({}), |
| 30 | + addLabels: jest.fn().mockResolvedValue({}), |
| 31 | + }, |
| 32 | + }, |
| 33 | + }; |
| 34 | +} |
| 35 | + |
| 36 | +const context = { |
| 37 | + repo: {owner: 'react', repo: 'react-native'}, |
| 38 | + payload: {issue: {number: 1}}, |
| 39 | +}; |
| 40 | + |
| 41 | +describe('checkForReproducer reproducer links', () => { |
| 42 | + test.each([ |
| 43 | + 'https://github.com/react/react-native/pull/58972', |
| 44 | + 'https://github.com/facebook/react-native/pull/58972', |
| 45 | + ])('accepts a pull request link as a reproducer: %s', async link => { |
| 46 | + const github = buildGithub(`Reproducer: ${link}`); |
| 47 | + |
| 48 | + await checkForReproducer(github, context); |
| 49 | + |
| 50 | + expect(github.rest.issues.removeLabel).toHaveBeenCalledWith( |
| 51 | + expect.objectContaining({name: 'Needs: Repro'}), |
| 52 | + ); |
| 53 | + expect(github.rest.issues.addLabels).not.toHaveBeenCalled(); |
| 54 | + }); |
| 55 | + |
| 56 | + test.each([ |
| 57 | + 'Reproducer: https://github.com/someone-else/some-repo/pull/12', |
| 58 | + 'It crashes when I scroll.', |
| 59 | + ])('asks for a reproducer when there is none: %s', async body => { |
| 60 | + const github = buildGithub(body); |
| 61 | + |
| 62 | + await checkForReproducer(github, context); |
| 63 | + |
| 64 | + expect(github.rest.issues.addLabels).toHaveBeenCalledWith( |
| 65 | + expect.objectContaining({ |
| 66 | + labels: ['Needs: Repro', 'Needs: Author Feedback'], |
| 67 | + }), |
| 68 | + ); |
| 69 | + expect(github.rest.issues.removeLabel).not.toHaveBeenCalled(); |
| 70 | + }); |
| 71 | +}); |
0 commit comments