mirror of
https://github.com/p-stream/providers.git
synced 2026-03-11 09:45:36 +00:00
158 lines
3.2 KiB
TypeScript
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,
|
|
);
|
|
});
|
|
});
|