Skip to content

Commit

Permalink
Merge #313: Added tests for a guest user to see the list page when th…
Browse files Browse the repository at this point in the history
…ere are no torrents in the index

6d6806d  refactor: [#310] change describe  to Users (Mario)
8e9b04c  refactor: [#310] fix minor typo in function name (Mario)
b1e9ab6 test: [#310] added tests for a guest user to see the list page when there are no torrents in the index (MMelchor)

Pull request description:

  Resolves #310.

ACKs for top commit:
  josecelano:
    ACK 6d6806d

Tree-SHA512: 5138f0b1a6ba3e4162c0ea30f78629abf879fbccbf2068949729ac1a353bd5e34ff57c29b370a664d367857b9de67ce29451660a1b92a204b10b2f11f75b3198
  • Loading branch information
josecelano committed Nov 16, 2023
2 parents b335a99 + 6d6806d commit 8b816ee
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 2 deletions.
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

0 comments on commit 8b816ee

Please sign in to comment.