@@ -812,3 +812,45 @@ func TestQueryBuilderV5(t *testing.T) {
812812 })
813813 }
814814}
815+
816+ func TestCreateDashboard (t * testing.T ) {
817+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
818+ assert .Equal (t , http .MethodPost , r .Method )
819+ assert .Equal (t , "/api/v1/dashboards" , r .URL .Path )
820+ assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
821+ assert .Equal (t , "test-api-key" , r .Header .Get ("SIGNOZ-API-KEY" ))
822+
823+ var body types.Dashboard
824+ err := json .NewDecoder (r .Body ).Decode (& body )
825+ require .NoError (t , err )
826+
827+ assert .NotEmpty (t , body .Title )
828+ assert .NotNil (t , body .Layout )
829+ assert .NotNil (t , body .Widgets )
830+
831+ w .WriteHeader (http .StatusOK )
832+ w .Write ([]byte (`{"status":"success","id":"dashboard-123"}` ))
833+ }))
834+ defer server .Close ()
835+
836+ logger , _ := zap .NewDevelopment ()
837+ client := NewClient (logger , server .URL , "test-api-key" )
838+
839+ d := types.Dashboard {
840+ Title : "whatever" ,
841+ Layout : []types.LayoutItem {},
842+ Widgets : []types.Widget {},
843+ }
844+
845+ ctx := context .Background ()
846+ resp , err := client .CreateDashboard (ctx , d )
847+ require .NoError (t , err )
848+
849+ var out map [string ]interface {}
850+ err = json .Unmarshal (resp , & out )
851+ require .NoError (t , err )
852+
853+ assert .Equal (t , "success" , out ["status" ])
854+ assert .Equal (t , "dashboard-123" , out ["id" ])
855+ }
856+
0 commit comments