Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump fetch-mock from 11.1.5 to 12.0.0 #1024

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions functions/classes/ExtensionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { Handler } from './Handler'

export class ExtensionHandler extends Handler {
constructor(githubToken, namespace, fetch = null) {
super(githubToken, fetch)
constructor(githubToken, namespace) {
super(githubToken)

this.namespace = namespace
}
Expand All @@ -16,7 +16,7 @@
return callback(null, response)
}

console.log(`Working on repo ${body.repository.full_name} for PR #${body.pull_request.number}`)

Check warning on line 19 in functions/classes/ExtensionHandler.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

const payload = {
success: {
Expand All @@ -35,7 +35,7 @@
try {
diffResponse = await got(body.pull_request.diff_url)
} catch (e) {
console.log(e.message)

Check warning on line 38 in functions/classes/ExtensionHandler.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

return callback(null, {
statusCode: 500,
Expand All @@ -52,7 +52,7 @@
if (/\.txt$/.test(diff.to) === false) {
payload.failure.description = `Fail: "${diff.to}" has not a txt extension`

console.log(`Fail: "${diff.to}" has not a txt extension`)

Check warning on line 55 in functions/classes/ExtensionHandler.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

return false
}
Expand Down
8 changes: 1 addition & 7 deletions functions/classes/Handler.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { Octokit } from '@octokit/rest'

export class Handler {
constructor(githubToken, fetch = null) {
constructor(githubToken) {
const options = {
auth: githubToken,
}

if (fetch) {
options.request = {
fetch,
}
}

this.githubClient = new Octokit(options)
}

Expand All @@ -32,14 +26,14 @@
message = `Hello ${body.sender.login}, the webhook is now enabled for ${body.repository.full_name}, enjoy!`
}

console.log(message)

Check warning on line 29 in functions/classes/Handler.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

return {
statusCode: 200,
body: message,
}
} catch (e) {
console.log(e.message)

Check warning on line 36 in functions/classes/Handler.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

return {
statusCode: 500,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@babel/core": "^7.25.9",
"@babel/eslint-parser": "^7.25.9",
"@babel/preset-env": "^7.25.9",
"@fetch-mock/jest": "^0.2.0",
"babel-loader": "^9.2.1",
"babel-plugin-source-map-support": "^2.2.0",
"eslint": "^8.57.1",
Expand All @@ -22,7 +23,6 @@
"eslint-plugin-jsx-a11y": "^6.10.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"fetch-mock": "^11.1.5",
"jest": "^29.7.0",
"nock": "^13.5.4",
"node-fetch": "2",
Expand Down
102 changes: 49 additions & 53 deletions tests/extension.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nock from 'nock'
import fetchMock from 'fetch-mock'
import fetchMock from '@fetch-mock/jest'
import { ExtensionHandler } from '../functions/classes/ExtensionHandler'
import { handler } from '../functions/extension'

Expand Down Expand Up @@ -124,12 +124,7 @@ describe('Validating extension', () => {
})

test('file extension is not txt', async () => {
const mock = fetchMock
.sandbox()
.mock(
'https://api.github.com/repos/foo/bar/statuses/ee55a1223ce20c3e7cb776349cb7f8efb7b88511',
200
)
fetchMock.mockGlobal().route('*', 200)

nock('http://git.hub').get('/diff').replyWithFile(200, `${__dirname}/fixtures/no_txt.diff`)

Expand All @@ -151,7 +146,7 @@ describe('Validating extension', () => {
},
}

const extension = new ExtensionHandler('GH_TOKEN', 'Test config', mock)
const extension = new ExtensionHandler('GH_TOKEN', 'Test config')
await extension.handle(githubEvent, callback)

expect(callback).toHaveBeenCalledTimes(1)
Expand All @@ -160,21 +155,20 @@ describe('Validating extension', () => {
statusCode: 204,
})

const lastOptions = JSON.parse(mock.lastOptions().body)
expect(lastOptions).toStrictEqual({
context: 'Test config - File extension check',
description: 'Fail: "theatlantic.com" has not a txt extension',
state: 'failure',
})
expect(fetch).toHaveFetched(
'https://api.github.com/repos/foo/bar/statuses/ee55a1223ce20c3e7cb776349cb7f8efb7b88511',
{
body: {
context: 'Test config - File extension check',
description: 'Fail: "theatlantic.com" has not a txt extension',
state: 'failure',
},
}
)
})

test('at least one file extension is not txt', async () => {
const mock = fetchMock
.sandbox()
.mock(
'https://api.github.com/repos/foo/bar/statuses/ee55a1223ce20c3e7cb776349cb7f8efb7b88511',
200
)
fetchMock.mockGlobal().route('*', 200)

nock('http://git.hub')
.get('/diff')
Expand All @@ -198,7 +192,7 @@ describe('Validating extension', () => {
},
}

const extension = new ExtensionHandler('GH_TOKEN', 'Test config', mock)
const extension = new ExtensionHandler('GH_TOKEN', 'Test config')
await extension.handle(githubEvent, callback)

expect(callback).toHaveBeenCalledTimes(1)
Expand All @@ -207,21 +201,20 @@ describe('Validating extension', () => {
statusCode: 204,
})

const lastOptions = JSON.parse(mock.lastOptions().body)
expect(lastOptions).toStrictEqual({
context: 'Test config - File extension check',
description: 'Fail: "wow.gamona.de" has not a txt extension',
state: 'failure',
})
expect(fetch).toHaveFetched(
'https://api.github.com/repos/foo/bar/statuses/ee55a1223ce20c3e7cb776349cb7f8efb7b88511',
{
body: {
context: 'Test config - File extension check',
description: 'Fail: "wow.gamona.de" has not a txt extension',
state: 'failure',
},
}
)
})

test('one deleted file', async () => {
const mock = fetchMock
.sandbox()
.mock(
'https://api.github.com/repos/foo/bar/statuses/ee55a1223ce20c3e7cb776349cb7f8efb7b88511',
200
)
fetchMock.mockGlobal().route('*', 200)

nock('http://git.hub')
.get('/diff')
Expand All @@ -245,7 +238,7 @@ describe('Validating extension', () => {
},
}

const extension = new ExtensionHandler('GH_TOKEN', 'Test config', mock)
const extension = new ExtensionHandler('GH_TOKEN', 'Test config')
await extension.handle(githubEvent, callback)

expect(callback).toHaveBeenCalledTimes(1)
Expand All @@ -254,21 +247,20 @@ describe('Validating extension', () => {
statusCode: 204,
})

const lastOptions = JSON.parse(mock.lastOptions().body)
expect(lastOptions).toStrictEqual({
context: 'Test config - File extension check',
description: 'passed',
state: 'success',
})
expect(fetch).toHaveFetched(
'https://api.github.com/repos/foo/bar/statuses/ee55a1223ce20c3e7cb776349cb7f8efb7b88511',
{
body: {
context: 'Test config - File extension check',
description: 'passed',
state: 'success',
},
}
)
})

test('file extension is ok', async () => {
const mock = fetchMock
.sandbox()
.mock(
'https://api.github.com/repos/foo/bar/statuses/ee55a1223ce20c3e7cb776349cb7f8efb7b88511',
200
)
fetchMock.mockGlobal().route('*', 200)

nock('http://git.hub').get('/diff').replyWithFile(200, `${__dirname}/fixtures/with_a.txt.diff`)

Expand All @@ -290,7 +282,7 @@ describe('Validating extension', () => {
},
}

const extension = new ExtensionHandler('GH_TOKEN', 'Test config', mock)
const extension = new ExtensionHandler('GH_TOKEN', 'Test config')
await extension.handle(githubEvent, callback)

expect(callback).toHaveBeenCalledTimes(1)
Expand All @@ -299,11 +291,15 @@ describe('Validating extension', () => {
statusCode: 204,
})

const lastOptions = JSON.parse(mock.lastOptions().body)
expect(lastOptions).toStrictEqual({
context: 'Test config - File extension check',
description: 'passed',
state: 'success',
})
expect(fetch).toHaveFetched(
'https://api.github.com/repos/foo/bar/statuses/ee55a1223ce20c3e7cb776349cb7f8efb7b88511',
{
body: {
context: 'Test config - File extension check',
description: 'passed',
state: 'success',
},
}
)
})
})
12 changes: 6 additions & 6 deletions tests/weblate.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fetchMock from 'fetch-mock'
import fetchMock from '@fetch-mock/jest'
import { WeblateHandler } from '../functions/classes/WeblateHandler'
import { handler } from '../functions/weblate'

Expand Down Expand Up @@ -123,9 +123,7 @@ describe('Apply label', () => {
})

test('PR is ok', async () => {
const mock = fetchMock
.sandbox()
.mock('https://api.github.com/repos/foo/bar/issues/42/labels', 200)
fetchMock.mockGlobal().route('*', 200)

const callback = jest.fn()
const githubEvent = {
Expand All @@ -147,7 +145,7 @@ describe('Apply label', () => {
},
}

const weblate = new WeblateHandler('GH_TOKEN', mock)
const weblate = new WeblateHandler('GH_TOKEN')
await weblate.handle(githubEvent, callback)

expect(callback).toHaveBeenCalledTimes(1)
Expand All @@ -156,6 +154,8 @@ describe('Apply label', () => {
statusCode: 204,
})

expect(mock.lastOptions().body).toBe('{"labels":["Translations"]}')
expect(fetch).toHaveFetched('https://api.github.com/repos/foo/bar/issues/42/labels', {
body: { labels: ['Translations'] },
})
})
})
32 changes: 23 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,13 @@
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.1.tgz#de633db3ec2ef6a3c89e2f19038063e8a122e2c2"
integrity sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==

"@fetch-mock/jest@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@fetch-mock/jest/-/jest-0.2.0.tgz#70fae50fd7886c313b0186c9d18165a80e080109"
integrity sha512-4oKbWKklbk7inBuK2YRtdjiJFG47N0VzkzTI9TOzY0g3q92605bwtcJXnAZ13gr4C0L0O/Bt24EIt0+aNDSd1Q==
dependencies:
fetch-mock "12.0.0"

"@hapi/accept@^6.0.1":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@hapi/accept/-/accept-6.0.3.tgz#eef0800a4f89cd969da8e5d0311dc877c37279ab"
Expand Down Expand Up @@ -4307,15 +4314,15 @@ fb-watchman@^2.0.0:
dependencies:
bser "2.1.1"

fetch-mock@^11.1.5:
version "11.1.5"
resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-11.1.5.tgz#77f78942f3733cfba47fc232b8528d1138a6761f"
integrity sha512-KHmZDnZ1ry0pCTrX4YG5DtThHi0MH+GNI9caESnzX/nMJBrvppUHMvLx47M0WY9oAtKOMiPfZDRpxhlHg89BOA==
fetch-mock@12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-12.0.0.tgz#d531e0c58aa3ecc04fa225fc4b624d070563dbc8"
integrity sha512-JSsjzoRN4rYqHa2/+8ushJGDsK9HGNTdBZo6Hrpu3KFN7Y03nRCt2VJ2WG4OUvyTUukOQ4TQIfjcFcEkMPGZ0Q==
dependencies:
"@types/glob-to-regexp" "^0.4.4"
dequal "^2.0.3"
glob-to-regexp "^0.4.1"
is-subset "^0.1.1"
is-subset-of "^3.1.10"
regexparam "^3.0.0"

file-entry-cache@^6.0.1:
Expand Down Expand Up @@ -4893,10 +4900,12 @@ is-string@^1.0.5, is-string@^1.0.7:
dependencies:
has-tostringtag "^1.0.0"

is-subset@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/is-subset/-/is-subset-0.1.1.tgz#8a59117d932de1de00f245fcdd39ce43f1e939a6"
integrity sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw==
is-subset-of@^3.1.10:
version "3.1.10"
resolved "https://registry.yarnpkg.com/is-subset-of/-/is-subset-of-3.1.10.tgz#d3f4331b9ca288318fae92ad5d953241b6f7b00b"
integrity sha512-avvaYgVmYWyaZ1NDFiv4y9JGkrE2je3op1Po4VYKKJKR8H2qVPsg1GZuuXl5elCTxTlwAIsrAjWAs4BVrISFRw==
dependencies:
typedescriptor "3.0.2"

is-symbol@^1.0.2, is-symbol@^1.0.3:
version "1.0.4"
Expand Down Expand Up @@ -6996,6 +7005,11 @@ typed-array-length@^1.0.6:
is-typed-array "^1.1.13"
possible-typed-array-names "^1.0.0"

typedescriptor@3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/typedescriptor/-/typedescriptor-3.0.2.tgz#9ad1715bc2be1cf063d5acbc4cd4bfc96d644225"
integrity sha512-hyVbaCUd18UiXk656g/imaBLMogpdijIEpnhWYrSda9rhvO4gOU16n2nh7xG5lv/rjumnZzGOdz0CEGTmFe0fQ==

unbox-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e"
Expand Down
Loading