Skip to content

Commit 706fc5b

Browse files
authored
Fix tests (#75)
* fix test * fix tests --------- Co-authored-by: Tomasz Smolarek <tomasz.smolarek@escolasoft.com>
1 parent c98efbc commit 706fc5b

File tree

3 files changed

+60
-39
lines changed

3 files changed

+60
-39
lines changed

tests/APIs/TopicTypesTutorCreateApiTest.php

+33-22
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function setUp(): void
4444
/**
4545
* @test
4646
*/
47-
public function testCreateTopicImage()
47+
public function testCreateTopicImage(): void
4848
{
4949
Storage::fake('local');
5050

@@ -70,7 +70,7 @@ public function testCreateTopicImage()
7070
]);
7171
}
7272

73-
public function testCreateTopicAudio()
73+
public function testCreateTopicAudio(): void
7474
{
7575
Storage::fake('local');
7676

@@ -97,7 +97,7 @@ public function testCreateTopicAudio()
9797
]);
9898
}
9999

100-
public function testCreateTopicPdf()
100+
public function testCreateTopicPdf(): void
101101
{
102102
Storage::fake();
103103

@@ -131,40 +131,51 @@ public function testCreateTopicPdf()
131131
]);
132132
}
133133

134-
public function testCreateTopicVideo()
134+
public function testCreateTopicVideo(): void
135135
{
136136
Storage::fake('local');
137137
Event::fake(TopicTypeChanged::class);
138138

139139
$file = new UploadedFile(__DIR__ . '/../mocks/video.mp4', 'video.mp4', 'video/mp4', null, true);
140140

141-
$this->response = $this->actingAs($this->user, 'api')
141+
$this->response = $this
142+
->actingAs($this->user, 'api')
142143
->withHeaders(['Accept' => 'application/json'])
143144
->post('/api/admin/topics', [
144145
'title' => 'Hello World',
145146
'lesson_id' => $this->lesson->id,
146147
'topicable_type' => Video::class,
147148
'value' => $file,
149+
])
150+
->assertJsonStructure([
151+
'data' => [
152+
'topicable' => [
153+
'id',
154+
'value',
155+
'url',
156+
'poster',
157+
'poster_url',
158+
'width',
159+
'height',
160+
'length'
161+
]
162+
]
148163
]);
149164

150165
$this->response->assertStatus(201);
151166

152167
$data = $this->response->getData()->data;
153168
$path = $data->topicable->value;
154169

155-
156170
Storage::disk('local')->assertExists('/' . $path);
157-
$this->assertDatabaseHas('topic_videos', [
158-
'value' => $path,
159-
'width' => 240,
160-
'height' => 240,
161-
'length' => 3667
162-
]);
171+
$this->assertEquals(240, $data->topicable->height);
172+
$this->assertEquals(240, $data->topicable->width);
173+
$this->assertEqualsWithDelta(3666, $data->topicable->length, 1);
163174

164175
Event::assertDispatched(TopicTypeChanged::class);
165176
}
166177

167-
public function testCreateTopicRichtext()
178+
public function testCreateTopicRichtext(): void
168179
{
169180
$this->response = $this->actingAs($this->user, 'api')
170181
->withHeaders(['Accept' => 'application/json'])
@@ -185,7 +196,7 @@ public function testCreateTopicRichtext()
185196
]);
186197
}
187198

188-
public function testCreateTopicH5P()
199+
public function testCreateTopicH5P(): void
189200
{
190201
Event::fake(TopicTypeChanged::class);
191202

@@ -211,7 +222,7 @@ public function testCreateTopicH5P()
211222
Event::assertDispatched(TopicTypeChanged::class);
212223
}
213224

214-
public function testCreateTopicScormSco()
225+
public function testCreateTopicScormSco(): void
215226
{
216227
Event::fake(TopicTypeChanged::class);
217228
$scormSco = ScormScoHelper::getScormSco();
@@ -237,7 +248,7 @@ public function testCreateTopicScormSco()
237248
Event::assertDispatched(TopicTypeChanged::class);
238249
}
239250

240-
public function testCreateTopicCmi5Au()
251+
public function testCreateTopicCmi5Au(): void
241252
{
242253
if (!class_exists(\EscolaLms\Cmi5\EscolaLmsCmi5ServiceProvider::class)) {
243254
$this->markTestSkipped('Require cmi5 package');
@@ -266,7 +277,7 @@ public function testCreateTopicCmi5Au()
266277
Event::assertDispatched(TopicTypeChanged::class);
267278
}
268279

269-
public function testCreateTopicOEmbed()
280+
public function testCreateTopicOEmbed(): void
270281
{
271282
Event::fake(TopicTypeChanged::class);
272283

@@ -291,7 +302,7 @@ public function testCreateTopicOEmbed()
291302
Event::assertDispatched(TopicTypeChanged::class);
292303
}
293304

294-
public function testCreateTopicNoLesson()
305+
public function testCreateTopicNoLesson(): void
295306
{
296307
$this->response = $this->withHeaders([
297308
'Accept' => 'application/json',
@@ -307,7 +318,7 @@ public function testCreateTopicNoLesson()
307318
$this->response->assertStatus(401);
308319
}
309320

310-
public function testCreateTopicImageNoFile()
321+
public function testCreateTopicImageNoFile(): void
311322
{
312323
$this->response = $this->actingAs($this->user, 'api')->withHeaders([
313324
'Accept' => 'application/json',
@@ -324,7 +335,7 @@ public function testCreateTopicImageNoFile()
324335
$this->response->assertStatus(422);
325336
}
326337

327-
public function testCreateTopicAudioNoFile()
338+
public function testCreateTopicAudioNoFile(): void
328339
{
329340
$this->response = $this->actingAs($this->user, 'api')->withHeaders([
330341
'Accept' => 'application/json',
@@ -341,7 +352,7 @@ public function testCreateTopicAudioNoFile()
341352
$this->response->assertStatus(422);
342353
}
343354

344-
public function testCreateTopicVideoNoFile()
355+
public function testCreateTopicVideoNoFile(): void
345356
{
346357
$course = Course::factory()->create();
347358

@@ -360,7 +371,7 @@ public function testCreateTopicVideoNoFile()
360371
$this->response->assertStatus(422);
361372
}
362373

363-
public function testCreateTopicWrongClass()
374+
public function testCreateTopicWrongClass(): void
364375
{
365376
$this->response = $this->actingAs($this->user, 'api')->withHeaders([
366377
'Accept' => 'application/json',

tests/APIs/TopicTypesTutorUpdateApiTest.php

+26-16
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,32 @@ public function testUpdateTopicVideo(): void
216216

217217
$file = new UploadedFile(__DIR__ . '/../mocks/video.mp4', 'video.mp4', 'video/mp4', null, true);
218218

219-
$this->response = $this->withHeaders([
220-
'Content' => 'application/x-www-form-urlencoded',
221-
'Accept' => 'application/json',
222-
])->actingAs($this->user, 'api')->post(
223-
'/api/admin/topics/'.$this->topic->id,
224-
[
219+
$this->response = $this
220+
->withHeaders([
221+
'Content' => 'application/x-www-form-urlencoded',
222+
'Accept' => 'application/json',
223+
])
224+
->actingAs($this->user, 'api')
225+
->post('/api/admin/topics/' . $this->topic->id, [
225226
'title' => 'Hello World',
226227
'lesson_id' => $this->topic->lesson_id,
227228
'topicable_type' => 'EscolaLms\TopicTypes\Models\TopicContent\Video',
228-
'value' => $file,
229-
]
230-
);
229+
'value' => $file
230+
])
231+
->assertJsonStructure([
232+
'data' => [
233+
'topicable' => [
234+
'id',
235+
'value',
236+
'url',
237+
'poster',
238+
'poster_url',
239+
'width',
240+
'height',
241+
'length'
242+
]
243+
]
244+
]);
231245

232246
$this->response->assertStatus(200);
233247

@@ -237,13 +251,9 @@ public function testUpdateTopicVideo(): void
237251
$path = $data->data->topicable->value;
238252

239253
Storage::disk('local')->assertExists('/'.$path);
240-
241-
$this->assertDatabaseHas('topic_videos', [
242-
'value' => $path,
243-
'width' => 240,
244-
'height' => 240,
245-
'length' => 3667
246-
]);
254+
$this->assertEquals(240, $data->data->topicable->height);
255+
$this->assertEquals(240, $data->data->topicable->width);
256+
$this->assertEqualsWithDelta(3666, $data->data->topicable->length, 1);
247257

248258
Event::assertDispatched(TopicTypeChanged::class, function ($event) {
249259
return $event->getUser() === $this->user && $event->getTopicContent();

tests/Commands/FillTopicTypeMetadataCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testFillTopicTypeMetadataCommand(): void
8484
$this->assertNotNull($topicable_video->length);
8585
$this->assertEquals(240, $topicable_video->width);
8686
$this->assertEquals(240, $topicable_video->height);
87-
$this->assertEquals(3667, $topicable_video->length);
87+
$this->assertEqualsWithDelta(3666, $topicable_video->length, 1);
8888

8989
// pdf
9090
$this->assertNotNull($topicable_pdf->length);

0 commit comments

Comments
 (0)