generated from linz/template-javascript-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#### Motivation Enable refactoring the handler arguments by verifying a common, simple use case. #### Modification - Mocks all relevant `GithubApi` methods to avoid any online calls. - Generates random input data to make it clear which parts of the input are relevant to the test (basically none of it is relevant). #### Checklist - [x] Tests updated - [ ] Docs updated (N/A) - [x] Issue linked in Title
- Loading branch information
Showing
3 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/commands/basemaps-github/__test__/create-pr-handler.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import assert from 'node:assert'; | ||
import { afterEach, it } from 'node:test'; | ||
|
||
import { TileSetType } from '@basemaps/config/build/config/tile.set.js'; | ||
import { EpsgCode } from '@basemaps/geo'; | ||
import { fsa } from '@chunkd/fs'; | ||
import { StacVersion } from 'stac-ts'; | ||
|
||
import { anySlug } from '../../../utils/__test__/slugify.test.js'; | ||
import { GithubApi } from '../../../utils/github.js'; | ||
import { basemapsCreatePullRequest, ConfigType, LinzBasemapsSourceCollectionRel } from '../create-pr.js'; | ||
import { Category } from '../make.cog.github.js'; | ||
|
||
const originalEnv = Object.assign({}, process.env); | ||
|
||
afterEach(() => { | ||
process.env = originalEnv; | ||
}); | ||
|
||
await it('basemapsCreatePullRequest.handler should handle S3 target', async (t) => { | ||
const targetUrl = `s3://linz-basemaps/${EpsgCode.Nztm2000}/${anySlug()}`; | ||
t.mock.method(fsa, 'readJson', () => { | ||
return Promise.resolve({ | ||
stac_version: '1.0.0' as StacVersion, | ||
type: 'Collection', | ||
id: 'b871c4a7-2d8e-4cec-997a-ed755cf542b9', | ||
title: 'any-title', | ||
description: 'any-description', | ||
license: 'any-license', | ||
extent: { spatial: { bbox: [[]] }, temporal: { interval: [[null, null]] } }, | ||
links: [ | ||
{ | ||
href: `s3://nz-imagery/${EpsgCode.Wgs84}/${anySlug()}`, | ||
rel: LinzBasemapsSourceCollectionRel, | ||
}, | ||
], | ||
}); | ||
}); | ||
process.env['GITHUB_API_TOKEN'] = 'any-github-api-token'; | ||
t.mock.method(GithubApi.prototype, 'getContent', () => { | ||
return Promise.resolve( | ||
Buffer.from( | ||
JSON.stringify({ | ||
type: TileSetType.Raster, | ||
format: 'avif', | ||
id: 'b48e08c3-ccef-4b42-870a-9c357cb15d1c', | ||
layers: [], | ||
name: 'any-name', | ||
title: 'any-title', | ||
}), | ||
), | ||
); | ||
}); | ||
t.mock.method(GithubApi.prototype, 'createBranch', () => {}); | ||
t.mock.method(GithubApi.prototype, 'createBlob', () => {}); | ||
t.mock.method(GithubApi.prototype, 'createCommit', () => {}); | ||
t.mock.method(GithubApi.prototype, 'updateBranch', () => {}); | ||
let createPullRequestCalled = false; | ||
t.mock.method(GithubApi.prototype, 'createPullRequest', () => { | ||
createPullRequestCalled = true; | ||
}); | ||
const targetUrlsString = JSON.stringify([targetUrl]); | ||
|
||
const result = await basemapsCreatePullRequest.handler({ | ||
target: targetUrlsString, | ||
repository: 'any-owner/any-repository', | ||
verbose: false, | ||
category: Category.Satellite, | ||
configType: ConfigType.Raster, | ||
individual: false, | ||
vector: false, | ||
ticket: 'any ticket', | ||
}); | ||
assert.equal(result, undefined); | ||
assert.ok(createPullRequestCalled); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters