pstreams-providers/src/__test__/standard/utils/features.test.ts
2026-01-27 12:52:05 -07:00

158 lines
3.2 KiB
TypeScript

import { FeatureMap, Flags, flags, flagsAllowedInFeatures } from '@/entrypoint/utils/targets';
import { describe, it, expect } from 'vitest';
describe('flagsAllowedInFeatures()', () => {
function checkFeatures(featureMap: FeatureMap, flags: Flags[], output: boolean) {
expect(flagsAllowedInFeatures(featureMap, flags)).toEqual(output);
}
it('should check required correctly', () => {
checkFeatures(
{
requires: [],
disallowed: [],
},
[],
true,
);
checkFeatures(
{
requires: [flags.CORS_ALLOWED],
disallowed: [],
},
[flags.CORS_ALLOWED],
true,
);
checkFeatures(
{
requires: [flags.CORS_ALLOWED],
disallowed: [],
},
[],
false,
);
checkFeatures(
{
requires: [flags.CORS_ALLOWED, flags.IP_LOCKED],
disallowed: [],
},
[flags.CORS_ALLOWED, flags.IP_LOCKED],
true,
);
checkFeatures(
{
requires: [flags.IP_LOCKED],
disallowed: [],
},
[flags.CORS_ALLOWED],
false,
);
checkFeatures(
{
requires: [flags.IP_LOCKED],
disallowed: [],
},
[],
false,
);
});
it('should check disallowed correctly', () => {
checkFeatures(
{
requires: [],
disallowed: [],
},
[],
true,
);
checkFeatures(
{
requires: [],
disallowed: [flags.CORS_ALLOWED],
},
[],
true,
);
checkFeatures(
{
requires: [],
disallowed: [flags.CORS_ALLOWED],
},
[flags.CORS_ALLOWED],
false,
);
checkFeatures(
{
requires: [],
disallowed: [flags.CORS_ALLOWED],
},
[flags.IP_LOCKED],
true,
);
checkFeatures(
{
requires: [],
disallowed: [flags.CORS_ALLOWED, flags.IP_LOCKED],
},
[flags.CORS_ALLOWED],
false,
);
});
it('should pass mixed tests', () => {
checkFeatures(
{
requires: [flags.CORS_ALLOWED],
disallowed: [flags.IP_LOCKED],
},
[],
false,
);
checkFeatures(
{
requires: [flags.CORS_ALLOWED],
disallowed: [flags.IP_LOCKED],
},
[flags.CORS_ALLOWED],
true,
);
checkFeatures(
{
requires: [flags.CORS_ALLOWED],
disallowed: [flags.IP_LOCKED],
},
[flags.IP_LOCKED],
false,
);
checkFeatures(
{
requires: [flags.CORS_ALLOWED],
disallowed: [flags.IP_LOCKED],
},
[flags.IP_LOCKED, flags.CORS_ALLOWED],
false,
);
});
it('should disallow MKV_REQUIRED for browser target (disallowed in features)', () => {
checkFeatures(
{ requires: [flags.CORS_ALLOWED], disallowed: [flags.MKV_REQUIRED] },
[flags.CORS_ALLOWED, flags.MKV_REQUIRED],
false,
);
checkFeatures(
{ requires: [flags.CORS_ALLOWED], disallowed: [flags.MKV_REQUIRED] },
[flags.CORS_ALLOWED],
true,
);
});
it('should allow MKV_REQUIRED for native target (no disallowed)', () => {
checkFeatures(
{ requires: [], disallowed: [] },
[flags.MKV_REQUIRED],
true,
);
});
});