{"size": 1439, "ext": "js", "max_stars_repo_path": "test/integration/sanity/Download.e2e.test.js", "max_stars_repo_name": "folloze/box-content-preview", "max_stars_repo_stars_event_min_datetime": "2017-07-13T06:07:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T11:59:44.000Z", "max_issues_repo_path": "test/integration/sanity/Download.e2e.test.js", "max_issues_repo_name": "folloze/box-content-preview", "max_issues_repo_issues_event_min_datetime": "2017-07-13T18:03:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-23T18:25:15.000Z", "max_forks_repo_path": "test/integration/sanity/Download.e2e.test.js", "max_forks_repo_name": "folloze/box-content-preview", "max_forks_repo_forks_event_min_datetime": "2017-07-13T03:31:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T18:03:34.000Z"}
{"max_stars_count": 94, "max_issues_count": 787, "max_forks_count": 86, "avg_line_length": 35.975, "max_line_length": 102, "alphanum_fraction": 0.5781792912}
// <reference types='Cypress' />
describe('Download disabled while preview is already open', () => {
    const token = Cypress.env('ACCESS_TOKEN');
    const fileIdBad = Cypress.env('FILE_ID_BAD');

    beforeEach(() => {
        cy.visit('/');
    });

    it('should give generic download error when trying to download and its forbidden', () => {
        cy.showPreview(token, fileIdBad, { showDownload: true });
        cy.route({
            method: 'GET',
            url: `**/files/${fileIdBad}?fields=download_url`,
            status: 403,
            response: {},
        });

        cy.getByTestId('preview-error-download-btn').should('be.visible');
        cy.getByTestId('preview-error-download-btn').click();
        cy.contains('Sorry! You can’t download this file.');
    });

    it('should give shield error when trying to download and access policy prevents download', () => {
        cy.showPreview(token, fileIdBad, { showDownload: true });
        cy.route({
            method: 'GET',
            url: `**/files/${fileIdBad}?fields=download_url`,
            status: 403,
            response: {
                code: 'forbidden_by_policy',
            },
        });

        cy.getByTestId('preview-error-download-btn').should('be.visible');
        cy.getByTestId('preview-error-download-btn').click();
        cy.contains('Downloading of this content has been disabled based on an access policy.');
    });
});
