/
dimamir
/
undb
Обзор
Документация
Войти
/
dimamir
/
undb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/domain/src/specification.test.ts
166 строк
5 KB
nichenqin
chore: prettier
14 май 2024, 04:57
14 май 2024, 04:57
5c0eb73
Код
Авторство
О чём код?
import { describe, expect, test } from "bun:test" import type { Result } from "oxide.ts" import { CompositeSpecification } from "./specification.js" describe("and", () => { test("should return true for matched senario", () => { class Test1 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 1 > 0 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } class Test2 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 2 > 0 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } const v = new Test1().and(new Test2()).isSatisfiedBy(undefined) expect(v).toBe(true) }) test("should return false for not matched senario", () => { class Test1 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 0 > 1 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } class Test2 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 2 > 0 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } const v = new Test1().and(new Test2()).isSatisfiedBy(undefined) expect(v).toBe(false) }) }) describe("or", () => { test("should return true for matched senario", () => { class Test1 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 1 > 0 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } class Test2 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 2 > 0 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } const v = new Test1().or(new Test2()).isSatisfiedBy(undefined) expect(v).toBe(true) }) test("should return true if any match", () => { class Test1 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 0 > 1 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } class Test2 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 2 > 0 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } const v = new Test1().or(new Test2()).isSatisfiedBy(undefined) expect(v).toBe(true) }) test("should return false if none match", () => { class Test1 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 0 > 1 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } class Test2 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return 0 > 1 } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } const v = new Test1().or(new Test2()).isSatisfiedBy(undefined) expect(v).toBe(false) }) }) describe("not", () => { test("should return reverse boolean value", () => { class Test1 extends CompositeSpecification { isSatisfiedBy(t: any): boolean { return true } mutate(t: any): Result<any, string> { throw new Error("Method not implemented.") } accept(v: any): Result<void, string> { throw new Error("Method not implemented.") } } const v = new Test1().not().isSatisfiedBy(undefined) expect(v).toBe(false) }) })