Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

테스트용 온톨로지 객체

TSv1 단위 테스트는 Objects.create()로 테스트용 객체를 만들고 속성을 넣어 함수 입력으로 사용할 수 있습니다. 일반 편집 API와 문법이 같지만 이 테스트 객체를 실제 온톨로지에 저장하는 작업은 아닙니다.

공항 이름 함수

가상의 ExampleDataAirport는 String 기본 키 airport와 String displayAirportName을 가진다고 가정합니다. src/airportNameFunctions.ts에 다음 함수를 두고 index.ts에서 클래스를 내보냅니다.

import { Function, UserFacingError } from "@foundry/functions-api";
import { ExampleDataAirport } from "@foundry/ontology-api";

export class AirportNameFunctions {
    @Function()
    public getAirportName(airport: ExampleDataAirport): string {
        if (airport.displayAirportName === undefined) {
            throw new UserFacingError("공항 이름이 없습니다.");
        }
        return airport.displayAirportName;
    }
}

객체를 만들고 전달

src/tests/airportNameFunctions.ts의 예제입니다. JFK Test와 공항 이름은 테스트 입력입니다.

import { AirportNameFunctions } from "../airportNameFunctions";
import { Objects } from "@foundry/ontology-api";

describe("airport names", () => {
    const functions = new AirportNameFunctions();

    test("reads the prepared airport name", () => {
        const airport = Objects.create().exampleDataAirport("JFK Test");
        airport.displayAirportName = "John F. Kennedy International";
        expect(functions.getAirportName(airport)).toEqual("John F. Kennedy International");
    });

    test("rejects an airport without a name", () => {
        const airport = Objects.create().exampleDataAirport("unnamed-test");
        expect(() => functions.getAirportName(airport)).toThrow("공항 이름이 없습니다.");
    });
});

객체의 상태를 준비하는 것과 함수가 만든 편집을 확인하는 것은 다릅니다. 편집 함수에는 verifyOntologyEditFunction을 사용하고 검색 결과를 바꾸려면 whenObjectSet을 사용합니다.