MCPcopy Create free account
hub / github.com/QuantumNous/new-api / TestApplyOriginTaskIntent

Function TestApplyOriginTaskIntent

middleware/task_plugin_origin_task_test.go:91–214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func TestApplyOriginTaskIntent(t *testing.T) {
92 setupOriginTaskDB(t)
93 enabled := insertOriginTaskChannel(t, common.ChannelStatusEnabled)
94 otherEnabled := insertOriginTaskChannel(t, common.ChannelStatusEnabled)
95 disabled := insertOriginTaskChannel(t, common.ChannelStatusManuallyDisabled)
96 insertOriginOwnedTask(t, "task-own", 7, enabled.Id, "origin-plugin")
97 insertOriginOwnedTask(t, "task-own-b", 7, enabled.Id, "origin-plugin")
98 insertOriginOwnedTask(t, "task-other-channel", 7, otherEnabled.Id, "origin-plugin")
99 insertOriginOwnedTask(t, "task-foreign", 8, enabled.Id, "origin-plugin")
100 insertOriginOwnedTask(t, "task-wrong-platform", 7, enabled.Id, "other-plugin")
101 insertOriginOwnedTask(t, "task-legacy", 7, enabled.Id, constant.TaskPlatform(strconv.Itoa(constant.ChannelTypeDoubaoVideo)))
102 insertOriginOwnedTask(t, "task-disabled", 7, disabled.Id, "origin-plugin")
103
104 tooMany := make([]any, 17)
105 for i := range tooMany {
106 tooMany[i] = fmt.Sprintf("task-%d", i)
107 }
108
109 tests := []struct {
110 name string
111 userID int
112 intent map[string]any
113 channelType int
114 wantCode string
115 wantPinned int
116 wantIDs []string
117 }{
118 {
119 name: "valid single origin id pins channel",
120 userID: 7,
121 intent: map[string]any{"originTaskIds": []any{"task-own"}},
122 wantPinned: enabled.Id,
123 wantIDs: []string{"task-own"},
124 },
125 {
126 name: "dedupes preserving first order",
127 userID: 7,
128 intent: map[string]any{"originTaskIds": []any{"task-own", " task-own ", "task-own-b"}},
129 wantPinned: enabled.Id,
130 wantIDs: []string{"task-own", "task-own-b"},
131 },
132 {
133 name: "legacy platform matches channelType",
134 userID: 7,
135 intent: map[string]any{"originTaskIds": []any{"task-legacy"}},
136 channelType: constant.ChannelTypeDoubaoVideo,
137 wantPinned: enabled.Id,
138 wantIDs: []string{"task-legacy"},
139 },
140 {
141 name: "unknown id",
142 userID: 7,
143 intent: map[string]any{"originTaskIds": []any{"task-missing"}},
144 wantCode: "origin_task_not_found",
145 },
146 {
147 name: "other user's task is not found",
148 userID: 7,

Callers

nothing calls this directly

Calls 10

TaskPlatformTypeAlias · 0.92
setupOriginTaskDBFunction · 0.85
insertOriginTaskChannelFunction · 0.85
insertOriginOwnedTaskFunction · 0.85
originTaskTestContextFunction · 0.85
applyOriginTaskIntentFunction · 0.85
resolvedOriginPinFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected