0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/packages/store/test/star-utils.test.ts
Juan Picado 99a1af1c35
vitest migration more packages (#4872)
* migrate storage package

* migrate middleware package

* migrate auth-memory plugin
2024-09-29 16:03:29 +02:00

60 lines
2 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { Manifest } from '@verdaccio/types';
import { generatePackageMetadata } from '../../api/node_modules/@verdaccio/test-helper/build';
import { isExecutingStarCommand } from '../src';
import { isStarManifest } from '../src';
describe('Star Utils', () => {
describe('isExecutingStarCommand', () => {
describe('disallow states', () => {
test('should not allow add star with no existing users', () => {
expect(isExecutingStarCommand({}, 'foo', false)).toBeFalsy();
});
test('should not allow add star with existing users', () => {
expect(isExecutingStarCommand({ bar: true }, 'foo', false)).toBeFalsy();
});
test('should fails if user already exist and us trying to add star', () => {
expect(isExecutingStarCommand({ foo: true }, 'foo', true)).toBeFalsy();
});
});
describe('allow states', () => {
test('should allow add star with existing users', () => {
expect(isExecutingStarCommand({ foo: true }, 'foo', false)).toBeTruthy();
});
test('should allow if is adding star and does not exist', () => {
expect(isExecutingStarCommand({ foo: true }, 'bar', true)).toBeTruthy();
});
});
});
describe('isStarManifest', () => {
test('is not star manifest', () => {
const pkg = generatePackageMetadata('foo');
expect(isStarManifest(pkg)).toBe(false);
});
test('is not star manifest empty users', () => {
const pkg = generatePackageMetadata('foo');
pkg.users = {};
expect(isStarManifest(pkg)).toBe(false);
});
test('is star manifest', () => {
const pkg = generatePackageMetadata('foo', '3.0.0') as Manifest;
// Staring a package usually is without versions and the user property within
// the manifest body
// @ts-expect-error
delete pkg.versions;
pkg.users = {
foo: true,
};
expect(isStarManifest(pkg)).toBe(true);
});
});
});