Tests

Artiplate ships with a some basic tests to ensure that the core functionality is working as expected. These tests are written using the Pest testing framework.

The tests are located in the tests/Feature and tests/Unit directories.

Below is an example of the test suite that tests that Magic Links works as expected.

test('new user is created when magic link is created', function () {
    app(CreateLoginMagicLinkAction::class)->execute('test@mail.dk');

    expect(User::where('email', 'test@mail.dk')->count())->toBe(1);
});

test('new user is not created when user exists and magic link is created', function () {
    $email = 'test@mail.dk';
    User::factory()->create([
        'email' => $email
    ]);

    app(CreateLoginMagicLinkAction::class)->execute($email);

    expect(User::where('email', $email)->count())->toBe(1);
});

test('magic link login can be created', function () {
    $magicLink = app(CreateLoginMagicLinkAction::class)->execute('test@mail.dk');

    expect($magicLink->url)->not->toBe(null);
    expect($magicLink->url)->toContain('magiclink');
});

test('magic link can be visited', function () {
    $magicLink = app(CreateLoginMagicLinkAction::class)->execute('test@mail.dk');

    $response = $this->get($magicLink->url);

    //redirected to verify email page
    $response->assertStatus(302);
});