Skip to content

Commit bd4000f

Browse files
committed
Only sort repository specifications
Respect remote versions specification ordering from config
1 parent 3eafc1f commit bd4000f

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

__test__/projects/GitHubProjectDataSource.test.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ test("It prioritizes main, master, develop, and development branch names when so
664664
expect(projects[0].versions[5].name).toEqual("anne")
665665
})
666666

667-
test("It sorts specifications alphabetically", async () => {
667+
test("It sorts file specifications alphabetically", async () => {
668668
const sut = new GitHubProjectDataSource({
669669
repositoryNameSuffix: "-openapi",
670670
repositoryDataSource: {
@@ -713,6 +713,45 @@ test("It sorts specifications alphabetically", async () => {
713713
expect(projects[0].versions[1].specifications[1].name).toEqual("o-openapi.yml")
714714
})
715715

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+
716755
test("It identifies the default branch in returned versions", async () => {
717756
const sut = new GitHubProjectDataSource({
718757
repositoryNameSuffix: "-openapi",
@@ -803,15 +842,15 @@ test("It adds remote versions from the project configuration", async () => {
803842
name: "Anne",
804843
isDefault: false,
805844
specifications: [{
806-
id: "dewey",
807-
name: "Dewey",
808-
url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/dewey.yml" })}`,
809-
isDefault: false
810-
}, {
811845
id: "huey",
812846
name: "Huey",
813847
url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/huey.yml" })}`,
814848
isDefault: false
849+
}, {
850+
id: "dewey",
851+
name: "Dewey",
852+
url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/dewey.yml" })}`,
853+
isDefault: false
815854
}]
816855
}, {
817856
id: "bobby",

src/features/projects/data/GitHubProjectDataSource.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
6666
return version.specifications.length > 0
6767
})
6868
.map(version => this.setDefaultSpecification(version, config?.defaultSpecificationName))
69-
.map(version => this.sortSpecificationsByName(version));
7069
const defaultName = repository.name.replace(new RegExp(this.repositoryNameSuffix + "$"), "")
7170
return {
7271
id: `${repository.owner}-${defaultName}`,
@@ -135,7 +134,7 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
135134
editURL: `https://github.com/${ownerName}/${repositoryName}/edit/${ref.name}/${file.name}`,
136135
isDefault: false // initial value
137136
}
138-
})
137+
}).sort((a, b) => a.name.localeCompare(b.name))
139138
return {
140139
id: ref.name,
141140
name: ref.name,

0 commit comments

Comments
 (0)