Skip to content

Commit

Permalink
Merge pull request clearlydefined#588 from qtomlinson/qt/fix_pod_late…
Browse files Browse the repository at this point in the history
…st_version

Fix fetching latest version for some pod components
  • Loading branch information
qtomlinson authored Aug 13, 2024
2 parents ae32c98 + 6a55052 commit dc8d5a2
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
6 changes: 5 additions & 1 deletion providers/fetch/podFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ class PodFetch extends AbstractFetch {
if (spec.revision) {
return versions.find(version => version.name === spec.revision)
} else {
return versions[versions.length - 1] // the versions are already sorted
return versions.sort((a, b) => {
const aDate = typeof a.created_at === 'string' ? a.created_at : ''
const bDate = typeof b.created_at === 'string' ? b.created_at : ''
return bDate.localeCompare(aDate)
})[0]
}
} else {
return null
Expand Down
124 changes: 124 additions & 0 deletions test/fixtures/pod/versions2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"versions": [
{
"name": "0.10.2",
"created_at": "2021-12-03 22:39:52 UTC"
},
{
"name": "0.11.0",
"created_at": "2021-12-22 06:52:38 UTC"
},
{
"name": "0.12.0",
"created_at": "2022-02-28 09:47:12 UTC"
},
{
"name": "0.13.0",
"created_at": "2022-05-27 10:49:32 UTC"
},
{
"name": "0.14.0",
"created_at": "2022-09-18 12:25:31 UTC"
},
{
"name": "0.15.0",
"created_at": "2022-10-08 12:30:37 UTC"
},
{
"name": "0.16.0",
"created_at": "2023-02-19 01:26:47 UTC"
},
{
"name": "0.17.0",
"created_at": "2023-02-19 01:45:57 UTC"
},
{
"name": "0.3.5",
"created_at": "2018-12-09 23:53:19 UTC"
},
{
"name": "0.3.6",
"created_at": "2018-12-15 05:56:51 UTC"
},
{
"name": "0.3.7",
"created_at": "2019-02-04 14:17:14 UTC"
},
{
"name": "0.3.8",
"created_at": "2019-04-07 00:47:43 UTC"
},
{
"name": "0.4.0",
"created_at": "2019-04-17 04:12:45 UTC"
},
{
"name": "0.4.1",
"created_at": "2019-04-17 08:25:41 UTC"
},
{
"name": "0.5.0",
"created_at": "2019-07-27 05:09:12 UTC"
},
{
"name": "0.6.0",
"created_at": "2019-09-16 22:38:50 UTC"
},
{
"name": "0.7.0",
"created_at": "2019-12-09 00:04:16 UTC"
},
{
"name": "0.7.1",
"created_at": "2019-12-21 05:26:01 UTC"
},
{
"name": "0.7.2",
"created_at": "2019-12-23 14:09:48 UTC"
},
{
"name": "0.7.3",
"created_at": "2020-01-19 09:15:23 UTC"
},
{
"name": "0.7.4",
"created_at": "2020-02-21 11:47:13 UTC"
},
{
"name": "0.7.5",
"created_at": "2020-03-09 01:16:13 UTC"
},
{
"name": "0.7.6",
"created_at": "2020-05-14 09:18:29 UTC"
},
{
"name": "0.8.0",
"created_at": "2020-05-26 02:32:55 UTC"
},
{
"name": "0.8.1",
"created_at": "2020-08-23 23:35:54 UTC"
},
{
"name": "0.9.0",
"created_at": "2020-12-19 10:14:22 UTC"
},
{
"name": "0.9.1",
"created_at": "2021-01-01 05:52:47 UTC"
}
],
"owners": [
{
"created_at": "2014-11-08 08:56:14 UTC",
"email": "[email protected]",
"name": "Thi Doan"
},
{
"created_at": "2022-01-08 12:04:30 UTC",
"email": "[email protected]",
"name": "Pedro Piñera¨"
}
]
}
11 changes: 10 additions & 1 deletion test/unit/providers/fetch/podFetchTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ describe('podFetch', () => {
return JSON.parse(fs.readFileSync(`test/fixtures/pod/${fileName}`))
}

const getVersionsStub = sinon.stub()
const PodFetch = proxyquire('../../../../providers/fetch/podFetch', {
requestretry: {
defaults: () => {
return {
get: sinon.stub().resolves({ body: loadJson('versions.json'), statusCode: 200 })
get: getVersionsStub
}
}
},
Expand All @@ -29,6 +30,7 @@ describe('podFetch', () => {
})

it('spec with version', async () => {
getVersionsStub.resolves({ body: loadJson('versions.json'), statusCode: 200 })
const result = await fetch.handle(new Request('test', 'cd:/pod/cocoapods/-/SwiftLCS/1.0'))
result.fetchResult.copyTo(result)
expect(result.url).to.be.equal('cd:/pod/cocoapods/-/SwiftLCS/1.0')
Expand All @@ -39,10 +41,17 @@ describe('podFetch', () => {
})

it('spec without version', async () => {
getVersionsStub.resolves({ body: loadJson('versions.json'), statusCode: 200 })
const result = await fetch.handle(new Request('test', 'cd:/pod/cocoapods/-/SwiftLCS'))
result.fetchResult.copyTo(result)
expect(result.url).to.be.equal('cd:/pod/cocoapods/-/SwiftLCS/1.3.4')
expect(result.document.releaseDate).to.be.equal('2019-04-10 00:22:10 UTC')
expect(result.casedSpec.toUrl()).to.be.equal('cd:/pod/cocoapods/-/SwiftLCS/1.3.4')
})

it('spec without version when version is lexically sorted', async () => {
getVersionsStub.resolves({ body: loadJson('versions2.json'), statusCode: 200 })
const version = await fetch._getVersion(new Request('test', 'cd:/pod/cocoapods/-/xcbeautify'))
expect(version.name).to.be.equal('0.17.0')
})
})

0 comments on commit dc8d5a2

Please sign in to comment.