diff --git a/__test__/projects/GitHubProjectDataSource.test.ts b/__test__/projects/GitHubProjectDataSource.test.ts index 19b9a668..12438c76 100644 --- a/__test__/projects/GitHubProjectDataSource.test.ts +++ b/__test__/projects/GitHubProjectDataSource.test.ts @@ -664,7 +664,7 @@ test("It prioritizes main, master, develop, and development branch names when so expect(projects[0].versions[5].name).toEqual("anne") }) -test("It sorts specifications alphabetically", async () => { +test("It sorts file specifications alphabetically", async () => { const sut = new GitHubProjectDataSource({ repositoryNameSuffix: "-openapi", repositoryDataSource: { @@ -713,6 +713,45 @@ test("It sorts specifications alphabetically", async () => { expect(projects[0].versions[1].specifications[1].name).toEqual("o-openapi.yml") }) +test("It maintains remote version specification ordering from config", async () => { + const sut = new GitHubProjectDataSource({ + repositoryNameSuffix: "-openapi", + repositoryDataSource: { + async getRepositories() { + return [{ + owner: "acme", + name: "foo-openapi", + defaultBranchRef: { + id: "12345678", + name: "main" + }, + configYaml: { + text: ` + name: Hello World + remoteVersions: + - name: Bar + specifications: + - id: some-spec + name: Zac + url: https://example.com/zac.yml + - id: another-spec + name: Bob + url: https://example.com/bob.yml + ` + }, + branches: [], + tags: [] + }] + } + }, + encryptionService: noopEncryptionService, + remoteConfigEncoder: base64RemoteConfigEncoder + }) + const projects = await sut.getProjects() + expect(projects[0].versions[0].specifications[0].name).toEqual("Zac") + expect(projects[0].versions[0].specifications[1].name).toEqual("Bob") +}) + test("It identifies the default branch in returned versions", async () => { const sut = new GitHubProjectDataSource({ repositoryNameSuffix: "-openapi", @@ -803,15 +842,15 @@ test("It adds remote versions from the project configuration", async () => { name: "Anne", isDefault: false, specifications: [{ - id: "dewey", - name: "Dewey", - url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/dewey.yml" })}`, - isDefault: false - }, { id: "huey", name: "Huey", url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/huey.yml" })}`, isDefault: false + }, { + id: "dewey", + name: "Dewey", + url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/dewey.yml" })}`, + isDefault: false }] }, { id: "bobby", diff --git a/src/features/projects/data/GitHubProjectDataSource.ts b/src/features/projects/data/GitHubProjectDataSource.ts index d5f90d62..97e6b8e8 100644 --- a/src/features/projects/data/GitHubProjectDataSource.ts +++ b/src/features/projects/data/GitHubProjectDataSource.ts @@ -66,7 +66,6 @@ export default class GitHubProjectDataSource implements IProjectDataSource { return version.specifications.length > 0 }) .map(version => this.setDefaultSpecification(version, config?.defaultSpecificationName)) - .map(version => this.sortSpecificationsByName(version)); const defaultName = repository.name.replace(new RegExp(this.repositoryNameSuffix + "$"), "") return { id: `${repository.owner}-${defaultName}`, @@ -135,7 +134,7 @@ export default class GitHubProjectDataSource implements IProjectDataSource { editURL: `https://github.com/${ownerName}/${repositoryName}/edit/${ref.name}/${file.name}`, isDefault: false // initial value } - }) + }).sort((a, b) => a.name.localeCompare(b.name)) return { id: ref.name, name: ref.name,