Skip to content

Commit 086b718

Browse files
authored
Merge branch 'develop' into dependabot/npm_and_yarn/multi-df16affa15
2 parents 96d7fe1 + 93d60b9 commit 086b718

File tree

2 files changed

+104
-8
lines changed

2 files changed

+104
-8
lines changed

__test__/projects/GitHubProjectDataSource.test.ts

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ test("It supports multiple OpenAPI specifications on a branch", async () => {
194194
id: "main",
195195
name: "main",
196196
specifications: [{
197-
id: "foo-service.yml",
198-
name: "foo-service.yml",
199-
url: "/api/blob/acme/foo-openapi/foo-service.yml?ref=12345678",
200-
editURL: "https://github.com/acme/foo-openapi/edit/main/foo-service.yml",
201-
isDefault: false
202-
}, {
203197
id: "bar-service.yml",
204198
name: "bar-service.yml",
205199
url: "/api/blob/acme/foo-openapi/bar-service.yml?ref=12345678",
@@ -211,6 +205,13 @@ test("It supports multiple OpenAPI specifications on a branch", async () => {
211205
url: "/api/blob/acme/foo-openapi/baz-service.yml?ref=12345678",
212206
editURL: "https://github.com/acme/foo-openapi/edit/main/baz-service.yml",
213207
isDefault: false
208+
},
209+
{
210+
id: "foo-service.yml",
211+
name: "foo-service.yml",
212+
url: "/api/blob/acme/foo-openapi/foo-service.yml?ref=12345678",
213+
editURL: "https://github.com/acme/foo-openapi/edit/main/foo-service.yml",
214+
isDefault: false
214215
}],
215216
url: "https://github.com/acme/foo-openapi/tree/main",
216217
isDefault: true
@@ -663,6 +664,94 @@ test("It prioritizes main, master, develop, and development branch names when so
663664
expect(projects[0].versions[5].name).toEqual("anne")
664665
})
665666

667+
test("It sorts file specifications alphabetically", async () => {
668+
const sut = new GitHubProjectDataSource({
669+
repositoryNameSuffix: "-openapi",
670+
repositoryDataSource: {
671+
async getRepositories() {
672+
return [{
673+
owner: "acme",
674+
name: "foo-openapi",
675+
defaultBranchRef: {
676+
id: "12345678",
677+
name: "main"
678+
},
679+
configYaml: {
680+
text: "name: Hello World"
681+
},
682+
branches: [{
683+
id: "12345678",
684+
name: "anne",
685+
files: [{
686+
name: "z-openapi.yml",
687+
}, {
688+
name: "a-openapi.yml",
689+
}, {
690+
name: "1-openapi.yml",
691+
}]
692+
}],
693+
tags: [{
694+
id: "12345678",
695+
name: "cathrine",
696+
files: [{
697+
name: "o-openapi.yml",
698+
}, {
699+
name: "2-openapi.yml",
700+
}]
701+
}]
702+
}]
703+
}
704+
},
705+
encryptionService: noopEncryptionService,
706+
remoteConfigEncoder: base64RemoteConfigEncoder
707+
})
708+
const projects = await sut.getProjects()
709+
expect(projects[0].versions[0].specifications[0].name).toEqual("1-openapi.yml")
710+
expect(projects[0].versions[0].specifications[1].name).toEqual("a-openapi.yml")
711+
expect(projects[0].versions[0].specifications[2].name).toEqual("z-openapi.yml")
712+
expect(projects[0].versions[1].specifications[0].name).toEqual("2-openapi.yml")
713+
expect(projects[0].versions[1].specifications[1].name).toEqual("o-openapi.yml")
714+
})
715+
716+
test("It maintains remote version specification ordering from config", async () => {
717+
const sut = new GitHubProjectDataSource({
718+
repositoryNameSuffix: "-openapi",
719+
repositoryDataSource: {
720+
async getRepositories() {
721+
return [{
722+
owner: "acme",
723+
name: "foo-openapi",
724+
defaultBranchRef: {
725+
id: "12345678",
726+
name: "main"
727+
},
728+
configYaml: {
729+
text: `
730+
name: Hello World
731+
remoteVersions:
732+
- name: Bar
733+
specifications:
734+
- id: some-spec
735+
name: Zac
736+
url: https://example.com/zac.yml
737+
- id: another-spec
738+
name: Bob
739+
url: https://example.com/bob.yml
740+
`
741+
},
742+
branches: [],
743+
tags: []
744+
}]
745+
}
746+
},
747+
encryptionService: noopEncryptionService,
748+
remoteConfigEncoder: base64RemoteConfigEncoder
749+
})
750+
const projects = await sut.getProjects()
751+
expect(projects[0].versions[0].specifications[0].name).toEqual("Zac")
752+
expect(projects[0].versions[0].specifications[1].name).toEqual("Bob")
753+
})
754+
666755
test("It identifies the default branch in returned versions", async () => {
667756
const sut = new GitHubProjectDataSource({
668757
repositoryNameSuffix: "-openapi",

src/features/projects/data/GitHubProjectDataSource.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
6565
).filter(version => {
6666
return version.specifications.length > 0
6767
})
68-
.map(version => this.setDefaultSpecification(version, config?.defaultSpecificationName));
68+
.map(version => this.setDefaultSpecification(version, config?.defaultSpecificationName))
6969
const defaultName = repository.name.replace(new RegExp(this.repositoryNameSuffix + "$"), "")
7070
return {
7171
id: `${repository.owner}-${defaultName}`,
@@ -134,7 +134,7 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
134134
editURL: `https://github.com/${ownerName}/${repositoryName}/edit/${ref.name}/${file.name}`,
135135
isDefault: false // initial value
136136
}
137-
})
137+
}).sort((a, b) => a.name.localeCompare(b.name))
138138
return {
139139
id: ref.name,
140140
name: ref.name,
@@ -259,4 +259,11 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
259259
}))
260260
}
261261
}
262+
263+
private sortSpecificationsByName(version: Version): Version {
264+
return {
265+
...version,
266+
specifications: version.specifications.sort((a, b) => a.name.localeCompare(b.name))
267+
}
268+
}
262269
}

0 commit comments

Comments
 (0)