Skip to content

Commit 9aff1c6

Browse files
committed
Use regular factory build function
1 parent 7365bb9 commit 9aff1c6

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

test/support/factory.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ defmodule Trento.Factory do
14611461
}
14621462
end
14631463

1464-
def random_ai_model do
1464+
def random_ai_model_factory(_) do
14651465
Trento.AI.AICase.stub_config_loader()
14661466

14671467
:all
@@ -1471,7 +1471,7 @@ defmodule Trento.Factory do
14711471

14721472
def ai_user_configuration_factory(attrs) do
14731473
user_id = Map.get(attrs, :user_id, 1)
1474-
model = Map.get(attrs, :model, random_ai_model())
1474+
model = Map.get(attrs, :model, build(:random_ai_model))
14751475

14761476
%UserConfiguration{}
14771477
|> UserConfiguration.changeset(%{

test/trento/ai/configurations_test.exs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ defmodule Trento.Ai.ConfigurationsTest do
66

77
alias Trento.AI.{Configurations, LLMRegistry, UserConfiguration}
88

9-
alias Trento.Factory
10-
119
import Trento.Factory
1210

1311
describe "creating a user AI configuration" do
@@ -20,7 +18,7 @@ defmodule Trento.Ai.ConfigurationsTest do
2018
Configurations.create_user_configuration(
2119
user,
2220
%{
23-
model: Factory.random_ai_model(),
21+
model: build(:random_ai_model),
2422
api_key: Faker.String.base64()
2523
}
2624
)
@@ -35,7 +33,7 @@ defmodule Trento.Ai.ConfigurationsTest do
3533
Configurations.create_user_configuration(
3634
user,
3735
%{
38-
model: Factory.random_ai_model(),
36+
model: build(:random_ai_model),
3937
api_key: Faker.String.base64()
4038
}
4139
)
@@ -48,7 +46,7 @@ defmodule Trento.Ai.ConfigurationsTest do
4846
Configurations.create_user_configuration(
4947
user,
5048
%{
51-
model: Factory.random_ai_model(),
49+
model: build(:random_ai_model),
5250
api_key: Faker.String.base64()
5351
}
5452
)
@@ -113,7 +111,7 @@ defmodule Trento.Ai.ConfigurationsTest do
113111
%{
114112
name: "missing api key",
115113
attrs: %{
116-
model: Factory.random_ai_model()
114+
model: build(:random_ai_model)
117115
},
118116
expected_errors: [
119117
api_key: {"can't be blank", [validation: :required]}
@@ -125,7 +123,7 @@ defmodule Trento.Ai.ConfigurationsTest do
125123
Enum.map(
126124
[nil, "", " "],
127125
&%{
128-
model: Factory.random_ai_model(),
126+
model: build(:random_ai_model),
129127
api_key: &1
130128
}
131129
),
@@ -139,7 +137,7 @@ defmodule Trento.Ai.ConfigurationsTest do
139137
Enum.map(
140138
[123, true, %{}, []],
141139
&%{
142-
model: Factory.random_ai_model(),
140+
model: build(:random_ai_model),
143141
api_key: &1
144142
}
145143
),
@@ -183,7 +181,7 @@ defmodule Trento.Ai.ConfigurationsTest do
183181
Configurations.create_user_configuration(
184182
user,
185183
%{
186-
model: random_ai_model(),
184+
model: build(:random_ai_model),
187185
api_key: Faker.String.base64()
188186
}
189187
)
@@ -192,7 +190,7 @@ defmodule Trento.Ai.ConfigurationsTest do
192190
test "should allow creating AI configuration with valid data" do
193191
%User{id: user_id} = user = insert(:user)
194192

195-
model = Factory.random_ai_model()
193+
model = build(:random_ai_model)
196194
api_key = Faker.String.base64()
197195

198196
expected_provider = LLMRegistry.get_model_provider(model)
@@ -225,7 +223,7 @@ defmodule Trento.Ai.ConfigurationsTest do
225223
assert {:error, :forbidden} ==
226224
Configurations.update_user_configuration(
227225
user,
228-
%{model: Factory.random_ai_model(), api_key: Faker.String.base64()}
226+
%{model: build(:random_ai_model), api_key: Faker.String.base64()}
229227
)
230228

231229
assert %UserConfiguration{} = load_ai_config(user_id)
@@ -238,7 +236,7 @@ defmodule Trento.Ai.ConfigurationsTest do
238236
assert {:error, :forbidden} =
239237
Configurations.update_user_configuration(
240238
user,
241-
%{model: Factory.random_ai_model(), api_key: Faker.String.base64()}
239+
%{model: build(:random_ai_model), api_key: Faker.String.base64()}
242240
)
243241
end
244242

@@ -248,7 +246,7 @@ defmodule Trento.Ai.ConfigurationsTest do
248246
assert {:error, :not_found} =
249247
Configurations.update_user_configuration(
250248
user,
251-
%{model: Factory.random_ai_model(), api_key: Faker.String.base64()}
249+
%{model: build(:random_ai_model), api_key: Faker.String.base64()}
252250
)
253251
end
254252

@@ -258,7 +256,7 @@ defmodule Trento.Ai.ConfigurationsTest do
258256
assert {:error, :not_found} =
259257
Configurations.update_user_configuration(
260258
user,
261-
%{model: Factory.random_ai_model(), api_key: Faker.String.base64()}
259+
%{model: build(:random_ai_model), api_key: Faker.String.base64()}
262260
)
263261
end
264262

@@ -353,7 +351,7 @@ defmodule Trento.Ai.ConfigurationsTest do
353351
api_key: initial_api_key
354352
} = insert(:ai_user_configuration, user_id: user_id)
355353

356-
new_model = Factory.random_ai_model()
354+
new_model = build(:random_ai_model)
357355

358356
expected_provider = LLMRegistry.get_model_provider(new_model)
359357

@@ -376,7 +374,7 @@ defmodule Trento.Ai.ConfigurationsTest do
376374

377375
insert(:ai_user_configuration, user_id: user_id)
378376

379-
new_model = Factory.random_ai_model()
377+
new_model = build(:random_ai_model)
380378
new_api_key = Faker.String.base64()
381379

382380
expected_provider = LLMRegistry.get_model_provider(new_model)

test/trento_web/controllers/v1/ai_configuration_controller_test.exs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
22
use TrentoWeb.ConnCase, async: true
33
use Trento.AI.AICase
44

5-
alias Trento.Factory
6-
75
alias Trento.AI.{LLMRegistry, UserConfiguration}
86

97
import Trento.Factory
@@ -123,7 +121,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
123121
%{
124122
name: "missing api_key",
125123
request_body: %{
126-
model: Factory.random_ai_model()
124+
model: build(:random_ai_model)
127125
},
128126
expected_errors: [
129127
%{
@@ -136,7 +134,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
136134
%{
137135
name: "nil api_key",
138136
request_body: %{
139-
model: Factory.random_ai_model(),
137+
model: build(:random_ai_model),
140138
api_key: nil
141139
},
142140
expected_errors: [
@@ -153,7 +151,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
153151
Enum.map(
154152
["", " "],
155153
&%{
156-
model: Factory.random_ai_model(),
154+
model: build(:random_ai_model),
157155
api_key: &1
158156
}
159157
),
@@ -171,7 +169,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
171169
Enum.map(
172170
[123, true, %{}, []],
173171
&%{
174-
model: Factory.random_ai_model(),
172+
model: build(:random_ai_model),
175173
api_key: &1
176174
}
177175
),
@@ -231,7 +229,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
231229
insert(:ai_user_configuration, user_id: user_id)
232230

233231
payload = %{
234-
model: Factory.random_ai_model(),
232+
model: build(:random_ai_model),
235233
api_key: Faker.String.base64(32)
236234
}
237235

@@ -257,7 +255,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
257255
conn: conn,
258256
api_spec: api_spec
259257
} do
260-
model = Factory.random_ai_model()
258+
model = build(:random_ai_model)
261259
api_key = Faker.String.base64()
262260

263261
expected_provider =
@@ -289,7 +287,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
289287
} do
290288
conn
291289
|> patch("/api/v1/profile/ai_configuration", %{
292-
model: Factory.random_ai_model(),
290+
model: build(:random_ai_model),
293291
api_key: Faker.String.base64()
294292
})
295293
|> json_response(:not_found)
@@ -383,7 +381,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
383381
%{
384382
name: "nil api_key",
385383
request_body: %{
386-
model: Factory.random_ai_model(),
384+
model: build(:random_ai_model),
387385
api_key: nil
388386
},
389387
expected_errors: [
@@ -400,7 +398,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
400398
Enum.map(
401399
["", " "],
402400
&%{
403-
model: Factory.random_ai_model(),
401+
model: build(:random_ai_model),
404402
api_key: &1
405403
}
406404
),
@@ -418,7 +416,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
418416
Enum.map(
419417
[123, true, %{}, []],
420418
&%{
421-
model: Factory.random_ai_model(),
419+
model: build(:random_ai_model),
422420
api_key: &1
423421
}
424422
),
@@ -485,7 +483,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
485483
provider: _initial_provider
486484
} = insert(:ai_user_configuration, user_id: user_id)
487485

488-
new_model = Factory.random_ai_model()
486+
new_model = build(:random_ai_model)
489487

490488
expected_provider =
491489
new_model
@@ -542,7 +540,7 @@ defmodule TrentoWeb.V1.AIConfigurationControllerTest do
542540
provider: _initial_provider
543541
} = insert(:ai_user_configuration, user_id: user_id)
544542

545-
new_model = Factory.random_ai_model()
543+
new_model = build(:random_ai_model)
546544

547545
expected_provider =
548546
new_model

0 commit comments

Comments
 (0)