Skip to content

Commit

Permalink
test:add unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhengxu2018 committed Jun 20, 2023
1 parent db34e1d commit 78be4f0
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,31 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test.
error: '[NOT_FOUND] @cnpm/[email protected] not found',
});
});

it('should not create sync task when package version tgz not exists and syncNotFound=false', async () => {
mock(app.config.cnpmcore, 'syncMode', 'exist');
mock(app.config.cnpmcore, 'syncNotFound', false);
mock(app.config.cnpmcore, 'redirectNotFound', false);
const res = await app.httpRequest()
.get('/lodash/-/lodash-1.404.404.tgz')
.set('user-agent', publisher.ua + ' node/16.0.0')
.set('Accept', 'application/vnd.npm.install-v1+json');
assert(res.status === 404);
app.notExpectLog('[middleware:ErrorHandler][syncPackage] create sync package');
});

it('should create sync task when package version tgz not exists and syncNotFound=true', async () => {
mock(app.config.cnpmcore, 'syncMode', 'exist');
mock(app.config.cnpmcore, 'syncNotFound', true);
mock(app.config.cnpmcore, 'redirectNotFound', false);
const res = await app.httpRequest()
.get('/lodash/-/lodash-1.404.404.tgz')
.set('user-agent', publisher.ua + ' node/16.0.0')
.set('Accept', 'application/vnd.npm.install-v1+json');
assert(res.status === 404);
app.expectLog('[middleware:ErrorHandler][syncPackage] create sync package');
});

});

describe('[GET /:fullname/download/:fullname-:version.tgz] deprecatedDownload()', () => {
Expand Down

0 comments on commit 78be4f0

Please sign in to comment.