Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions __test__/projects/GitHubProjectDataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/features/projects/data/GitHubProjectDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down Expand Up @@ -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,
Expand Down