-
Notifications
You must be signed in to change notification settings - Fork 91
feat: remove package version files #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coolyuantao
wants to merge
2
commits into
cnpm:master
Choose a base branch
from
coolyuantao:fix/remove-version-files
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
test/port/controller/PackageVersionFileController/removeFiles.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import assert from 'node:assert/strict'; | ||
import { app, mock } from '@eggjs/mock/bootstrap'; | ||
|
||
import { TestUtil, type TestUser } from '../../../../test/TestUtil.js'; | ||
|
||
describe('test/port/controller/PackageVersionFileController/removeFiles.test.ts', () => { | ||
let publisher: TestUser; | ||
let adminUser: TestUser; | ||
beforeEach(async () => { | ||
publisher = await TestUtil.createUser(); | ||
adminUser = await TestUtil.createAdmin(); | ||
}); | ||
|
||
describe('[DELETE /:fullname/:versionSpec/files] removeFiles()', () => { | ||
it('should 404 when enableUnpkg = false', async () => { | ||
mock(app.config.cnpmcore, 'allowPublishNonScopePackage', true); | ||
coolyuantao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mock(app.config.cnpmcore, 'enableUnpkg', false); | ||
coolyuantao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const pkg = await TestUtil.getFullPackage({ | ||
name: 'foo', | ||
version: '1.0.0', | ||
versionObject: { | ||
description: 'work with utf8mb4 💩, 𝌆 utf8_unicode_ci, foo𝌆bar 🍻', | ||
}, | ||
}); | ||
await app | ||
.httpRequest() | ||
.put(`/${pkg.name}`) | ||
.set('authorization', publisher.authorization) | ||
.set('user-agent', publisher.ua) | ||
.send(pkg) | ||
.expect(201); | ||
const res = await app | ||
.httpRequest() | ||
.delete('/foo/1.0.0/files') | ||
.set('authorization', adminUser.authorization) | ||
.expect(404) | ||
.expect('content-type', 'application/json; charset=utf-8'); | ||
assert.equal(res.body.error, '[NOT_FOUND] Not Found'); | ||
}); | ||
|
||
it('should work', async () => { | ||
mock(app.config.cnpmcore, 'allowPublishNonScopePackage', true); | ||
mock(app.config.cnpmcore, 'enableUnpkg', true); | ||
mock(app.config.cnpmcore, 'enableSyncUnpkgFiles', true); | ||
coolyuantao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
app.mockLog(); | ||
|
||
const pkg = await TestUtil.getFullPackage({ | ||
name: 'foo', | ||
version: '1.0.0', | ||
versionObject: { | ||
description: 'work with utf8mb4 💩, 𝌆 utf8_unicode_ci, foo𝌆bar 🍻', | ||
}, | ||
}); | ||
|
||
// publish package | ||
await app | ||
.httpRequest() | ||
.put(`/${pkg.name}`) | ||
.set('authorization', publisher.authorization) | ||
.set('user-agent', publisher.ua) | ||
.send(pkg) | ||
.expect(201); | ||
const pkgResponse = await app | ||
.httpRequest() | ||
.get(`/${pkg.name}/1.0.0`) | ||
.expect(200); | ||
const publishTime = new Date(pkgResponse.body.publish_time).toISOString(); | ||
|
||
// sync package version files | ||
await app | ||
.httpRequest() | ||
.put(`/${pkg.name}/1.0.0/files`) | ||
.set('authorization', adminUser.authorization) | ||
.expect(200) | ||
.expect('content-type', 'application/json; charset=utf-8'); | ||
await app | ||
.httpRequest() | ||
.get(`/${pkg.name}/1.0.0/files/package.json`) | ||
.expect(200); | ||
|
||
// remove package version files | ||
const packageVersionFilesDeleteResponse = await app | ||
.httpRequest() | ||
.delete(`/${pkg.name}/1.0.0/files`) | ||
.set('authorization', adminUser.authorization) | ||
.expect(200) | ||
.expect('content-type', 'application/json; charset=utf-8'); | ||
assert.deepEqual(packageVersionFilesDeleteResponse.body, [ | ||
{ | ||
path: `/packages/${pkg.name}/1.0.0/files/package.json`, | ||
type: 'file', | ||
contentType: 'application/json', | ||
integrity: | ||
'sha512-yTg/L7tUtFK54aNH3iwgIp7sF3PiAcUrIEUo06bSNq3haIKRnagy6qOwxiEmtfAtNarbjmEpl31ZymySsECi3Q==', | ||
lastModified: publishTime, | ||
size: 209, | ||
}, | ||
]); | ||
app.expectLog( | ||
`DELETE /${pkg.name}/1.0.0/files] [nfsAdapter:remove] key: /packages/foo/1.0.0/files/package.json` | ||
); | ||
app.expectLog( | ||
`DELETE /${pkg.name}/1.0.0/files] [PackageVersionFileRepository:removePackageVersionFiles:remove] 1 rows in PackageVersionFile` | ||
); | ||
app.expectLog( | ||
`DELETE /${pkg.name}/1.0.0/files] [PackageVersionFileRepository:removePackageVersionFiles:remove] 1 rows in Dist` | ||
); | ||
|
||
// remove again | ||
const packageVersionFilesDeleteResponse2 = await app | ||
.httpRequest() | ||
.delete(`/${pkg.name}/1.0.0/files`) | ||
.set('authorization', adminUser.authorization) | ||
.expect(200) | ||
.expect('content-type', 'application/json; charset=utf-8'); | ||
assert.deepEqual(packageVersionFilesDeleteResponse2.body, []); | ||
app.expectLog( | ||
`DELETE /${pkg.name}/1.0.0/files] [PackageVersionFileRepository:removePackageVersionFiles:remove] 0 rows in PackageVersionFile` | ||
); | ||
app.notExpectLog( | ||
`DELETE /${pkg.name}/1.0.0/files] [PackageVersionFileRepository:removePackageVersionFiles:remove] 0 rows in Dist` | ||
); | ||
}); | ||
|
||
it('should 404 when package not exists', async () => { | ||
const res = await app | ||
.httpRequest() | ||
.delete('/@cnpm/foonot-exists/1.0.40000404/files') | ||
.set('authorization', adminUser.authorization) | ||
.expect(404); | ||
assert.equal( | ||
res.body.error, | ||
'[NOT_FOUND] @cnpm/foonot-exists@1.0.40000404 not found' | ||
); | ||
}); | ||
|
||
it('should 403 when non-admin request', async () => { | ||
const res = await app | ||
.httpRequest() | ||
.delete('/@cnpm/foonot-exists/1.0.40000404/files') | ||
.expect(403); | ||
assert.equal(res.body.error, '[FORBIDDEN] Not allow to access'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.