Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.5 KB
Raw Blame
// SiYuan - https://github.com/siyuan-note/siyuan
// Copyright (c) 2020-present, b3log.org
// SPDX-License-Identifier: AGPL-3.0-or-later

package api

import (
	"bytes"
	"net/http"
	"testing"

	"github.com/siyuan-note/siyuan/kernel/apicontract"
	"github.com/siyuan-note/siyuan/kernel/av"
)

func TestAVContractLunarField(t *testing.T) {
	fixture := setupAttributeViewContextFilterAPITest(t)
	key := av.NewKey("20261009120000-lunara1", "Birthday", "", av.KeyTypeDate)
	key.DateFormat = av.DateDisplayFormatLunar
	fixture.attrView.KeyValues = append(fixture.attrView.KeyValues, &av.KeyValues{Key: key, Values: []*av.Value{}})
	fixture.attrView.Views[0].Table.Columns = append(fixture.attrView.Views[0].Table.Columns,
		&av.ViewTableColumn{BaseField: &av.BaseField{ID: key.ID}})
	if err := av.SaveAttributeView(fixture.attrView); err != nil {
		t.Fatal(err)
	}
	path := "/api/av/renderAttributeView"
	response := callAttributeViewContextFilterAPI(t, path, map[string]any{
		"id": fixture.attrView.ID, "blockID": fixture.databaseID, "ignoreRows": true,
	}, renderAttributeView)
	if !bytes.Contains(response.Body.Bytes(), []byte(`"dateFormat":"lunar"`)) {
		t.Fatalf("lunar field missing from response: %s", response.Body.String())
	}
	bundle, err := apicontract.BuildBundle()
	if err != nil {
		t.Fatal(err)
	}
	if err = bundle.ValidateHTTPResponse(http.MethodPost, path, response.Code,
		response.Header().Get("Content-Type"), response.Body.Bytes()); err != nil {
		t.Fatalf("lunar response violates contract: %v", err)
	}
}