|
1 |
| -import { MAIN_BRANCH } from '../../../common'; |
| 1 | +import * as common from '../../../common'; |
2 | 2 | import { cleanGeneratedBranch } from '../cleanGeneratedBranch';
|
3 | 3 | import { pushGeneratedCode } from '../pushGeneratedCode';
|
4 | 4 | import commentText from '../text';
|
5 | 5 | import {
|
6 |
| - getCommentBody, |
7 | 6 | upsertGenerationComment,
|
| 7 | + getCommentBody, |
8 | 8 | } from '../upsertGenerationComment';
|
9 | 9 |
|
10 |
| -jest.mock('../../../common', () => ({ |
11 |
| - ...(jest.requireActual('../../../common') as any), |
12 |
| - run: jest.fn().mockResolvedValue('mocked'), |
13 |
| -})); |
14 |
| - |
15 | 10 | describe('codegen', () => {
|
16 | 11 | describe('cleanGeneratedBranch', () => {
|
17 | 12 | it('throws without parameters', async () => {
|
@@ -68,13 +63,41 @@ describe('codegen', () => {
|
68 | 63 | `);
|
69 | 64 | });
|
70 | 65 |
|
71 |
| - it('returns the right comment for a `cleanup` trigger', async () => { |
72 |
| - expect(await getCommentBody('cleanup')).toMatchInlineSnapshot(` |
73 |
| - "### ✗ The generated branch has been deleted. |
| 66 | + describe('cleanup', () => { |
| 67 | + let mockedResolvedValue: string; |
| 68 | + beforeEach(() => { |
| 69 | + jest.spyOn(common, 'run').mockImplementation(() => { |
| 70 | + return Promise.resolve(mockedResolvedValue); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + afterEach(() => { |
| 75 | + jest.spyOn(common, 'run').mockRestore(); |
| 76 | + }); |
| 77 | + |
| 78 | + afterEach(() => {}); |
| 79 | + it('returns the right comment for a `cleanup` trigger', async () => { |
| 80 | + mockedResolvedValue = 'mocked'; |
74 | 81 |
|
75 |
| - If the PR has been merged, you can check the generated code on the [\`${MAIN_BRANCH}\` branch](https://github.com/algolia/api-clients-automation/tree/${MAIN_BRANCH}). |
76 |
| - You can still access [the last generated commit](https://github.com/algolia/api-clients-automation/commit/mocked)." |
77 |
| - `); |
| 82 | + expect(await getCommentBody('cleanup')).toMatchInlineSnapshot(` |
| 83 | + "### ✗ The generated branch has been deleted. |
| 84 | +
|
| 85 | + If the PR has been merged, you can check the generated code on the [\`${common.MAIN_BRANCH}\` branch](https://github.com/algolia/api-clients-automation/tree/${common.MAIN_BRANCH}). |
| 86 | + You can still access the code generated on \`mocked\` via [this commit](https://github.com/algolia/api-clients-automation/commit/mocked)." |
| 87 | + `); |
| 88 | + }); |
| 89 | + |
| 90 | + it('fallbacks to the env variable HEAD_BRANCH if found when we are on `main`', async () => { |
| 91 | + process.env.HEAD_BRANCH = 'myFakeBranch'; |
| 92 | + mockedResolvedValue = 'main'; |
| 93 | + |
| 94 | + expect(await getCommentBody('cleanup')).toMatchInlineSnapshot(` |
| 95 | + "### ✗ The generated branch has been deleted. |
| 96 | +
|
| 97 | + If the PR has been merged, you can check the generated code on the [\`${common.MAIN_BRANCH}\` branch](https://github.com/algolia/api-clients-automation/tree/${common.MAIN_BRANCH}). |
| 98 | + You can still access the code generated on \`generated/myFakeBranch\` via [this commit](https://github.com/algolia/api-clients-automation/commit/main)." |
| 99 | + `); |
| 100 | + }); |
78 | 101 | });
|
79 | 102 |
|
80 | 103 | describe('text', () => {
|
|
0 commit comments