Skip to content

Commit

Permalink
Update to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Dec 21, 2024
1 parent b99b58e commit 5593f70
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/commands/pipelines/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import HTTP from 'http-call'
import {getCoupling, getPipeline, getReleases, listPipelineApps, SDK_HEADER} from '../../lib/api'
import KolkrabbiAPI from '../../lib/pipelines/kolkrabbi-api'
import type {OciImage, Slug, Pipeline, PipelineCoupling} from '../../lib/types/fir'
import type {Commit, GitHubDiff} from '../../lib/types/github'

interface AppInfo {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {APIClient} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import {App, Pipeline, PipelineCoupling, Release} from './types/fir'
import {App, Pipeline, PipelineCoupling} from './types/fir'

export const V3_HEADER = 'application/vnd.heroku+json; version=3'
export const SDK_HEADER = 'application/vnd.heroku+json; version=3.sdk'
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/lib/types/github.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface GitHubUser {
export interface GitHubUser {
login: string;
id: number;
node_id: string;
Expand All @@ -20,21 +20,21 @@ interface GitHubUser {
site_admin: boolean;
}

interface CommitPerson {
export interface CommitPerson {
name: string;
email: string;
date: string;
}

interface Verification {
export interface Verification {
verified: boolean;
reason: string;
signature: string;
payload: string;
verified_at: string;
}

interface CommitDetails {
export interface CommitDetails {
author: CommitPerson;
committer: CommitPerson;
message: string;
Expand All @@ -47,13 +47,13 @@ interface CommitDetails {
verification: Verification;
}

interface CommitParent {
export interface CommitParent {
sha: string;
url: string;
html_url: string;
}

interface CommitFile {
export interface CommitFile {
sha: string;
filename: string;
status: string;
Expand All @@ -66,7 +66,7 @@ interface CommitFile {
patch: string;
}

interface Commit {
export interface Commit {
sha: string;
node_id: string;
commit: CommitDetails;
Expand All @@ -78,7 +78,7 @@ interface Commit {
parents: CommitParent[];
}

interface GitHubDiff {
export interface GitHubDiff {
url: string;
html_url: string;
permalink_url: string;
Expand Down
24 changes: 24 additions & 0 deletions packages/cli/test/unit/commands/pipelines/diff.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ describe('pipelines:diff', function () {
const kolkrabbiApi = 'https://kolkrabbi.heroku.com'
const githubApi = 'https://api.github.com'

const pipelineWithGeneration = {
generation: {name: 'cedar'},
}

const pipeline = {
id: '123-pipeline-456',
name: 'example-pipeline',
Expand Down Expand Up @@ -186,6 +190,11 @@ describe('pipelines:diff', function () {
.post('/filters/apps')
.reply(200, [targetApp])
})
.nock(apiUrl, api => {
api
.get(`/pipelines/${targetCoupling.pipeline.id}`)
.reply(200, pipelineWithGeneration)
})
.command(['pipelines:diff', `--app=${targetApp.name}`])
.catch(error => {
expect(error.message).to.contain('no downstream apps')
Expand All @@ -207,6 +216,11 @@ describe('pipelines:diff', function () {
.get(`/apps/${downstreamApp2.id}/github`)
.reply(200, downstreamApp2Github)
})
.nock(apiUrl, api => {
api
.get(`/pipelines/${targetCoupling.pipeline.id}`)
.reply(200, pipelineWithGeneration)
})
}

mockedTest(test)
Expand Down Expand Up @@ -282,6 +296,11 @@ describe('pipelines:diff', function () {
{slug: {id: downstreamSlugId}, status: 'succeeded'},
])
})
.nock(apiUrl, api => {
api
.get(`/pipelines/${targetCoupling.pipeline.id}`)
.reply(200, pipelineWithGeneration)
})
}

mockedTest(test)
Expand Down Expand Up @@ -352,6 +371,11 @@ describe('pipelines:diff', function () {
{oci_image: {id: downstreamOciImageId}, status: 'succeeded'},
])
})
.nock(apiUrl, api => {
api
.get(`/pipelines/${targetFirCoupling.pipeline.id}`)
.reply(200, {generation: {name: 'fir'}})
})
}

mockedTest(test)
Expand Down

0 comments on commit 5593f70

Please sign in to comment.