Skip to content

Commit

Permalink
test: fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhengxu2018 committed Oct 24, 2024
1 parent e5ca2d1 commit 8137f5f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 118 deletions.
88 changes: 1 addition & 87 deletions test/core/service/ProxyCacheService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,92 +127,6 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
});
});

describe('getRewrittenManifest()', () => {
it('should get full package manifest', async () => {
const data = await TestUtil.readJSONFile(
TestUtil.getFixtures('registry.npmjs.org/foobar.json'),
);
mock(proxyCacheService, 'getUpstreamFullManifests', async () => {
return {
status: 200,
data,
};
});
const manifest = await proxyCacheService.getRewrittenManifest(
'foobar',
DIST_NAMES.FULL_MANIFESTS,
);
const versionArr = Object.values(manifest.versions);
for (const i of versionArr) {
assert(i.dist.tarball.includes('http://localhost:7001'));
}
});

it('should get abbreviated package manifest', async () => {
const data = await TestUtil.readJSONFile(
TestUtil.getFixtures('registry.npmjs.org/abbreviated_foobar.json'),
);
mock(proxyCacheService, 'getUpstreamAbbreviatedManifests', async () => {
return {
status: 200,
data,
};
});
const manifest = await proxyCacheService.getRewrittenManifest(
'foobar',
DIST_NAMES.ABBREVIATED_MANIFESTS,
);
const versionArr = Object.values(manifest.versions);
for (const i of versionArr) {
assert(i.dist.tarball.includes('http://localhost:7001'));
}
});

it('should get full package version manifest', async () => {
const data = await TestUtil.readJSONFile(
TestUtil.getFixtures('registry.npmjs.org/foobar/1.0.0/package.json'),
);
mock(proxyCacheService, 'getUpstreamPackageVersionManifest', async () => {
return {
status: 200,
data,
};
});
const manifest = await proxyCacheService.getRewrittenManifest(
'foobar',
DIST_NAMES.MANIFEST,
'1.0.0',
);
assert(manifest.dist);
assert(manifest.dist.tarball.includes('http://localhost:7001'));
});

it('should get abbreviated package version manifest', async () => {
const data = await TestUtil.readJSONFile(
TestUtil.getFixtures(
'registry.npmjs.org/foobar/1.0.0/abbreviated.json',
),
);
mock(
proxyCacheService,
'getUpstreamAbbreviatedPackageVersionManifest',
async () => {
return {
status: 200,
data,
};
},
);
const manifest = await proxyCacheService.getRewrittenManifest(
'foobar',
DIST_NAMES.ABBREVIATED,
'1.0.0',
);
assert(manifest.dist);
assert(manifest.dist.tarball.includes('http://localhost:7001'));
});
});

describe('removeProxyCache()', () => {
it('should remove cache', async () => {
await proxyCacheRepository.saveProxyCache(
Expand Down Expand Up @@ -300,7 +214,7 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
fileType: DIST_NAMES.FULL_MANIFESTS,
},
);
mock(proxyCacheService, 'getUpstreamFullManifests', async () => {
mock(proxyCacheService, 'getPackageVersionManifest', async () => {
return {
status: 200,
data: await TestUtil.readJSONFile(
Expand Down
31 changes: 0 additions & 31 deletions test/port/controller/ProxyCacheController/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,35 +157,4 @@ describe('test/port/controller/PackageVersionFileController/listFiles.test.ts',
.expect(404);
});
});

describe('[DELETE /-/proxy-cache] truncateProxyCaches()', () => {
it('should 403 when syncMode !== proxy', async () => {
const adminUser = await TestUtil.createAdmin();
await app
.httpRequest()
.delete('/-/proxy-cache')
.set('authorization', adminUser.authorization)
.expect(403);
});

it('should 403 when not login', async () => {
mock(app.config.cnpmcore, 'syncMode', SyncMode.proxy);
mock(app.config.cnpmcore, 'redirectNotFound', false);
await app.httpRequest().delete('/-/proxy-cache').expect(401);
});

it('should delete all packages about "foo-bar".', async () => {
mock(app.config.cnpmcore, 'syncMode', SyncMode.proxy);
mock(app.config.cnpmcore, 'redirectNotFound', false);
const adminUser = await TestUtil.createAdmin();
const res = await app
.httpRequest()
.delete('/-/proxy-cache')
.set('authorization', adminUser.authorization)
.expect(200);
assert(res.body.ok === true);
const res1 = await app.httpRequest().get('/-/proxy-cache').expect(200);
assert(res1.body.data.length === 0);
});
});
});

0 comments on commit 8137f5f

Please sign in to comment.