Skip to content

Commit

Permalink
fix integration tests deleting dev db
Browse files Browse the repository at this point in the history
  • Loading branch information
emmachughes committed Nov 14, 2023
1 parent de320f8 commit 3c608df
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 36 deletions.
22 changes: 22 additions & 0 deletions localSetup/projects/nginx/templates/hub.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ server {

server_name
hub.${EDLIB_ROOT_DOMAIN}
hub-test.${EDLIB_ROOT_DOMAIN}
hub-vite-hmr.${EDLIB_ROOT_DOMAIN}
~^edlib-hub[a-z0-9-]+\.ngrok\.dev$
;
Expand All @@ -29,6 +30,27 @@ server {
}
}

server {
listen 443 ssl;
server_name hub-test.${EDLIB_ROOT_DOMAIN};

ssl_certificate /etc/ssl/private/cerpus.crt;
ssl_certificate_key /etc/ssl/private/cerpus.key;

root /srv/www/hub/public;

location / {
try_files $uri /index.php$is_args$args;
}

location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass hub:9000;
fastcgi_param APP_ENV 'testing';
fastcgi_param APP_URL https://hub-test.${EDLIB_ROOT_DOMAIN};
}
}

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
Expand Down
1 change: 1 addition & 0 deletions scripts/update-host-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $ip\tca.$root
$ip\tdocs.$root
$ip\tfacade.$root
$ip\thub.$root
$ip\thub-test.$root
$ip\thub-vite-hmr.$root
$ip\tmailpit.$root
$ip\tmoodle.$root
Expand Down
16 changes: 16 additions & 0 deletions sourcecode/hub/.env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
APP_KEY=base64:VaYy17usaDFlRZRAO9OQukSy6rpcCKlooovrAc55x6s=
APP_NAME=EdlibTest
APP_URL=https://hub-test.edlib.test
BCRYPT_ROUNDS=4
DB_HOST=postgres
DB_DATABASE=hub_test
DB_USERNAME=postgres
DB_PASSWORD=thepgpassword
FEATURE_RESET_PASSWORD_ENABLED=true
FEATURE_SIGNUP_ENABLED=true
MAIL_MAILER=array
MEILISEARCH_HOST=http://meilisearch:7700
MEILISEARCH_KEY=masterkey1234567
QUEUE_CONNECTION=sync
SCOUT_PREFIX=hub_test_
TELESCOPE_ENABLED=false
7 changes: 2 additions & 5 deletions sourcecode/hub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ TODO: write the rest of the README
./chromedriver --allowed-ips= --allowed-origins='*'
```

4. Make sure APP_URL is set to the correct location. It should be the URL you
open in your browser for development.
4. Make sure <https://hub-test.edlib.test> loads in your browser. It should look
the same as the regular hub, but should not share data with it.

```dotenv
APP_URL=https://hub.edlib.test
```
5. Run the browser tests.

## Using ngrok for development
Expand Down
15 changes: 1 addition & 14 deletions sourcecode/hub/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,9 @@
</include>
</coverage>
<php>
<!-- These values don't affect Edlib inside Dusk -->
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:VaYy17usaDFlRZRAO9OQukSy6rpcCKlooovrAc55x6s="/>
<env name="APP_NAME" value="EdlibTest" />
<env name="APP_URL" value="https://hub.edlib.test/"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<!-- FIXME: does not work with Dusk -->
<!-- <env name="DB_DATABASE" value="hub_test"/>-->
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="FEATURE_RESET_PASSWORD_ENABLED" value="true"/>
<env name="FEATURE_SIGNUP_ENABLED" value="true"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SCOUT_PREFIX" value="hub_test_"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
3 changes: 0 additions & 3 deletions sourcecode/hub/tests/Browser/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@

use App\Models\LtiTool;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

final class AdminTest extends DuskTestCase
{
use DatabaseMigrations;

public function testCanRebuildIndex(): void
{
$this->browse(function (Browser $browser) {
Expand Down
3 changes: 0 additions & 3 deletions sourcecode/hub/tests/Browser/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
namespace Tests\Browser;

use App\Models\Content;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

final class ContentTest extends DuskTestCase
{
use DatabaseMigrations;

public function testPreviewsContent(): void
{
$content = Content::factory()
Expand Down
3 changes: 0 additions & 3 deletions sourcecode/hub/tests/Browser/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

use App\Models\Content;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Hash;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

final class UserTest extends DuskTestCase
{
use DatabaseMigrations;

public function testUserCanSignUp(): void
{
$this->browse(function (Browser $browser) {
Expand Down
2 changes: 2 additions & 0 deletions sourcecode/hub/tests/DuskTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Foundation\Testing\DatabaseTruncation;
use Laravel\Dusk\TestCase as BaseTestCase;

use function assert;
Expand All @@ -15,6 +16,7 @@
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
use DatabaseTruncation;

/**
* Create the RemoteWebDriver instance.
Expand Down
2 changes: 1 addition & 1 deletion sourcecode/hub/tests/Feature/LtiPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testItemSelectionLaunchContainsPlatformDetails(): void
$this->assertSame('Edlib', $request->get('tool_consumer_info_product_family_code'));
$this->assertSame('3', $request->get('tool_consumer_info_version'));
$this->assertSame('EdlibTest', $request->get('tool_consumer_instance_name'));
$this->assertSame('https://hub.edlib.test/', $request->get('tool_consumer_instance_url'));
$this->assertSame('https://hub-test.edlib.test', $request->get('tool_consumer_instance_url'));
}

public function testItemSelectionLaunchContainsLocale(): void
Expand Down
14 changes: 7 additions & 7 deletions sourcecode/hub/tests/Feature/LtiToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testCookieCheckIsTransparentWhenCookiesAllowed(): void
$platform = LtiPlatform::factory()->create();

$request = $this->oauthSigner->sign(
new Request('POST', 'https://hub.edlib.test/lti/1.1/select', [
new Request('POST', 'https://hub-test.edlib.test/lti/1.1/select', [
'content_item_return_url' => 'http://example.com/',
'lti_message_type' => 'ContentItemSelectionRequest',
]),
Expand All @@ -53,15 +53,15 @@ public function testCookieCheckIsTransparentWhenCookiesAllowed(): void
->assertLocation('/lti/1.1/select');

$this->post('/lti/1.1/select', $request->toArray())
->assertRedirect('https://hub.edlib.test/content');
->assertRedirect('https://hub-test.edlib.test/content');
}

public function testCookieCheckShowsCountermeasuresWhenCookiesNotAllowed(): void
{
$platform = LtiPlatform::factory()->create();

$request = $this->oauthSigner->sign(
new Request('POST', 'https://hub.edlib.test/lti/1.1/select', [
new Request('POST', 'https://hub-test.edlib.test/lti/1.1/select', [
'content_item_return_url' => 'http://example.com/',
'lti_message_type' => 'ContentItemSelectionRequest',
]),
Expand All @@ -83,7 +83,7 @@ public function testAuthorizedItemSelectionRequestsRedirectToContentExplorer():
$platform = LtiPlatform::factory()->create();

$request = $this->oauthSigner->sign(
new Request('POST', 'https://hub.edlib.test/lti/1.1/select', [
new Request('POST', 'https://hub-test.edlib.test/lti/1.1/select', [
'content_item_return_url' => 'http://example.com/',
'lti_message_type' => 'ContentItemSelectionRequest',
]),
Expand All @@ -92,13 +92,13 @@ public function testAuthorizedItemSelectionRequestsRedirectToContentExplorer():

$this->withCookie('_edlib_cookies', '1')
->post('/lti/1.1/select', $request->toArray())
->assertRedirect('https://hub.edlib.test/content');
->assertRedirect('https://hub-test.edlib.test/content');
}

public function testUnauthorizedItemSelectionRequestsAreRejected(): void
{
$request = $this->oauthSigner->sign(
new Request('POST', 'https://hub.edlib.test/lti/1.1/select', [
new Request('POST', 'https://hub-test.edlib.test/lti/1.1/select', [
'content_item_return_url' => 'http://example.com/',
'lti_message_type' => 'ContentItemSelectionRequest',
]),
Expand All @@ -115,7 +115,7 @@ public function testReportsErrorsToToolConsumer(): void
$platform = LtiPlatform::factory()->create();

$request = $this->oauthSigner->sign(
new Request('POST', 'https://hub.edlib.test/lti/1.1/select', [
new Request('POST', 'https://hub-test.edlib.test/lti/1.1/select', [
'launch_presentation_return_url' => 'https://example.com/return',
'lti_message_type' => 'basic-lti-launch-request',
]),
Expand Down

0 comments on commit 3c608df

Please sign in to comment.