Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from "cypress";
import { grantAdminRole, deleteUser } from "./cypress/e2e/contexts/user/tasks";
import { deleteTorrent } from "./cypress/e2e/contexts/torrent/tasks";
import { deleteTorrent, deleteTorrentsInfoFromDatabase } from "./cypress/e2e/contexts/torrent/tasks";
import { deleteCategory, addCategory } from "./cypress/e2e/contexts/category/tasks";
import { DatabaseConfig } from "./cypress/e2e/common/database";

Expand All @@ -26,6 +26,9 @@ export default defineConfig({
deleteTorrent: ({ infohash }) => {
return deleteTorrent(infohash, databaseConfig(config));
},
deleteTorrentsInfoFromDatabase: () => {
return deleteTorrentsInfoFromDatabase(databaseConfig(config));
},
// User context
grantAdminRole: ({ username }) => {
return grantAdminRole(username, databaseConfig(config));
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/contexts/torrent/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ Cypress.Commands.add("delete_torrent_from_database_and_fixture", (torrent_info,
// Delete the torrent file in the fixtures folder
cy.exec(`rm ${torrent_info.path}`);
});

Cypress.Commands.add("clear_torrents_info_from_database", () => {
cy.task("deleteTorrentsInfoFromDatabase");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { baseURL } from "nuxt/dist/core/runtime/nitro/paths";

describe("Users", () => {
before(() => {
// Deletes all torrents and their related info from the database so the test can pass
cy.clear_torrents_info_from_database();
});

it("Should be able to see the list page when there are no torrents", () => {
cy.visit("/torrents");
cy.url().should("match", /\/torrents$/);
cy.get("[data-cy=\"no-results-element\"]").invoke("text").should("match", /No results./i);
});
});
66 changes: 66 additions & 0 deletions cypress/e2e/contexts/torrent/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,69 @@ function deleteTorrentQuery (infohash: string): DatabaseQuery {
params: [infohash]
};
}

// Task to delete all torrents from the database before running any test
export const deleteTorrentsInfoFromDatabase = async (db_config: DatabaseConfig): Promise<Boolean> => {
try {
await runDatabaseQuery(clearTorrentsTableQuery(), db_config);
await runDatabaseQuery(clearAnnounceUrlsTableQuery(), db_config);
await runDatabaseQuery(clearTorrentFilesTableQuery(), db_config);
await runDatabaseQuery(clearTorrentInfoTableQuery(), db_config);
await runDatabaseQuery(clearTorrentInfoHashesTableQuery(), db_config);
await runDatabaseQuery(clearTagLinkTableQuery(), db_config);
await runDatabaseQuery(clearTrackerStatsTableQuery(), db_config);
return true;
} catch (err) {
return await Promise.reject(err);
}
};

// Database query specifications
function clearTorrentsTableQuery (): DatabaseQuery {
return {
query: "DELETE FROM torrust_torrents",
params: []
};
}

function clearAnnounceUrlsTableQuery (): DatabaseQuery {
return {
query: "DELETE FROM torrust_torrent_announce_urls",
params: []
};
}

function clearTorrentFilesTableQuery (): DatabaseQuery {
return {
query: "DELETE FROM torrust_torrent_files",
params: []
};
}

function clearTorrentInfoTableQuery (): DatabaseQuery {
return {
query: "DELETE FROM torrust_torrent_info",
params: []
};
}

function clearTorrentInfoHashesTableQuery (): DatabaseQuery {
return {
query: "DELETE FROM torrust_torrent_info_hashes",
params: []
};
}

function clearTagLinkTableQuery (): DatabaseQuery {
return {
query: "DELETE FROM torrust_torrent_tag_links",
params: []
};
}

function clearTrackerStatsTableQuery (): DatabaseQuery {
return {
query: "DELETE FROM torrust_torrent_tracker_stats",
params: []
};
}
1 change: 1 addition & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare global {
// Torrent context
upload_torrent(torrent_info: TestTorrentInfo): Chainable<void>
delete_torrent_from_database_and_fixture(torrent_info: TestTorrentInfo, infohash: string): Chainable<void>
clear_torrents_info_from_database(): Chainable<void>;

// Category context
delete_category_from_database(name: string): Chainable<void>
Expand Down
2 changes: 1 addition & 1 deletion pages/torrents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<Pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :total-results="torrentsTotal" />
</template>
<template v-else>
<span class="text-neutral-content">No results.</span>
<span data-cy="no-results-element" class="text-neutral-content">No results.</span>
</template>
</div>
</div>
Expand Down