Files
moeka-project/scripts/sponsorkit/sponsorkitOpenCollectivePatch.test.js
T
nanakura dc26878386
CI / Lint (push) Canceled after 0s
CI / Build Test (stage-web) (push) Canceled after 0s
CI / Build Test (ui-loading-screens) (push) Canceled after 0s
CI / Build Test (ui-transitions) (push) Canceled after 0s
CI / Unit Test (push) Canceled after 0s
CI / Type Check (push) Canceled after 0s
CI / Check Provenance (push) Canceled after 0s
Sync Labels / sync-labels (push) Successful in 1m43s
chore: prune unused apps and services for the moeka fork
- Remove stage-tamagotchi, stage-pocket, server, and engine workspaces with their workflows, addons, and docs
- Switch the toolchain from pnpm to bun, replace lockfiles with bun.lock
- Rewrite remaining product references to Moeka
2026-09-14 16:40:49 +07:00

84 lines
2.2 KiB
JavaScript

import { ProvidersMap } from 'sponsorkit'
import { afterEach, describe, expect, it, vi } from 'vitest'
/**
* Creates a minimal OpenCollective GraphQL response for SponsorKit's fetch flow.
*
* @param {'orders' | 'transactions'} nodeType - The OpenCollective connection requested by SponsorKit.
*/
function createGraphqlResponse(nodeType) {
return new Response(JSON.stringify({
data: {
account: {
[nodeType]: {
nodes: [],
totalCount: 0,
},
},
},
}), {
headers: {
'Content-Type': 'application/json',
},
})
}
/**
* Normalizes fetch init headers so the test can assert browser-style header names.
*
* @param {HeadersInit | undefined} headers - Headers passed by ofetch to the platform fetch API.
*/
function normalizeHeaders(headers) {
return new Headers(headers)
}
/**
* @example SponsorKit sends OpenCollective personal tokens through the documented HTTP header.
*/
describe('sponsorKit OpenCollective patch', () => {
afterEach(() => {
vi.unstubAllGlobals()
})
/**
* @example A personal token is sent as Personal-Token, not as the legacy Api-Key header.
*/
it('uses the OpenCollective Personal-Token header for GraphQL requests', async () => {
const requests = []
vi.stubGlobal('fetch', vi.fn(async (url, init) => {
requests.push({
url,
headers: normalizeHeaders(init?.headers),
})
return createGraphqlResponse(requests.length === 1 ? 'orders' : 'transactions')
}))
await ProvidersMap.opencollective.fetchSponsors({
includePastSponsors: true,
opencollective: {
key: 'personal-token-example',
slug: 'proj-airi',
},
})
/**
* @example expect SponsorKit to request both OpenCollective orders and transactions.
*/
expect(requests).toHaveLength(2)
for (const request of requests) {
/**
* @example expect every GraphQL request to use OpenCollective's Personal-Token auth header.
*/
expect(request.headers.get('Personal-Token')).toBe('personal-token-example')
/**
* @example expect SponsorKit not to send the deprecated Api-Key header for personal tokens.
*/
expect(request.headers.has('Api-Key')).toBe(false)
}
})
})