Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presigned url #3724

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
more tests
  • Loading branch information
RulaKhaled committed Jul 5, 2022
commit eb8ceaad13cd1cd60b146a7f92aa599245ad93c1
85 changes: 59 additions & 26 deletions src/pages/CommitPage/UploadsCard/Upload.spec.js
Original file line number Diff line number Diff line change
@@ -2,14 +2,23 @@ import { render, screen } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from 'react-query'
import { MemoryRouter, Route } from 'react-router-dom'

import { useUploadPresignedUrl } from 'services/uploadPresignedUrl'
import { formatTimeToNow } from 'shared/utils/dates'

import Upload from './Upload'

jest.mock('services/uploadPresignedUrl')

const queryClient = new QueryClient()
const mockedPresignedUrl = {
presignedUrl:
'http://minio:9000/archive/v4/raw/2022-06-23/942173DE95CBF167C5683F40B7DB34C0/ee3ecad424e67419d6c4531540f1ef5df045ff12/919ccc6d-7972-4895-b289-f2d569683a17.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=codecov-default-key%2F20220705%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220705T101702Z&X-Amz-Expires=10&X-Amz-SignedHeaders=host&X-Amz-Signature=8846492d85f62187493cbff3631ec7f0ccf2d355f768eecf294f0572cf758e4c',
}

describe('UploadsCard', () => {
function setup(props) {
function setup({ props, data = mockedPresignedUrl }) {
useUploadPresignedUrl.mockReturnValue({ data })

render(
<MemoryRouter initialEntries={['/gh/codecov/test']}>
<Route path="/:provider/:owner/:repo">
@@ -24,11 +33,13 @@ describe('UploadsCard', () => {
describe('renders', () => {
beforeEach(() => {
setup({
ciUrl: 'ciUrl.com',
createdAt: '2020-08-25T16:36:19.559474+00:00',
downloadUrl: 'download.com',
buildCode: '1234',
uploadType: 'CARRIEDFORWARD',
props: {
ciUrl: 'ciUrl.com',
createdAt: '2020-08-25T16:36:19.559474+00:00',
downloadUrl: 'download.com',
buildCode: '1234',
uploadType: 'CARRIEDFORWARD',
},
})
})

@@ -59,7 +70,7 @@ describe('UploadsCard', () => {

describe('build without build link', () => {
beforeEach(() => {
setup({ buildCode: '1234' })
setup({ props: { buildCode: '1234' } })
})
it('renders a the build code', () => {
expect(screen.getByText(/1234/)).toBeInTheDocument()
@@ -72,7 +83,7 @@ describe('UploadsCard', () => {
})
describe('missinng data renders', () => {
beforeEach(() => {
setup({})
setup({ props: {}, data: null })
})

it('renders a default build code if no code was provided', () => {
@@ -92,13 +103,17 @@ describe('UploadsCard', () => {
describe('rendering flags', () => {
it('one flag', () => {
setup({
flags: ['flag1'],
props: {
flags: ['flag1'],
},
})
expect(screen.getByText(/flag1/)).toBeInTheDocument()
})
it('multiple flags', () => {
setup({
flags: ['flag1', 'flag2', 'flag3', 'flag4'],
props: {
flags: ['flag1', 'flag2', 'flag3', 'flag4'],
},
})
expect(screen.getByText(/flag1/)).toBeInTheDocument()
expect(screen.getByText(/flag2/)).toBeInTheDocument()
@@ -114,70 +129,88 @@ describe('UploadsCard', () => {

it('fileNotFoundInStorage error', () => {
setup({
errors: [{ errorCode: 'FILE_NOT_IN_STORAGE' }],
props: {
errors: [{ errorCode: 'FILE_NOT_IN_STORAGE' }],
},
})
expect(screen.getByText(/processing failed/)).toBeInTheDocument()
})
it('reportExpired error', () => {
setup({
errors: [{ errorCode: 'REPORT_EXPIRED' }],
props: {
errors: [{ errorCode: 'REPORT_EXPIRED' }],
},
})
expect(screen.getByText(/upload expired/)).toBeInTheDocument()
})
it('reportEmpty error', () => {
setup({
errors: [{ errorCode: 'REPORT_EMPTY' }],
props: {
errors: [{ errorCode: 'REPORT_EMPTY' }],
},
})
expect(screen.getByText(/upload is empty/)).toBeInTheDocument()
})
it('all errors', () => {
setup({
errors: [
{ errorCode: 'FILE_NOT_IN_STORAGE' },
{ errorCode: 'REPORT_EXPIRED' },
{ errorCode: 'REPORT_EMPTY' },
{ errorCode: 'SOME_NEW_ERROR' },
],
props: {
errors: [
{ errorCode: 'FILE_NOT_IN_STORAGE' },
{ errorCode: 'REPORT_EXPIRED' },
{ errorCode: 'REPORT_EMPTY' },
{ errorCode: 'SOME_NEW_ERROR' },
],
},
})
expect(screen.getByText(/processing failed/)).toBeInTheDocument()
expect(screen.getByText(/upload expired/)).toBeInTheDocument()
expect(screen.getByText(/upload is empty/)).toBeInTheDocument()
})
it('handles new errors the front end doesnt know how to handle', () => {
setup({
errors: [{ errorCode: 'SOME_NEW_ERROR' }],
props: {
errors: [{ errorCode: 'SOME_NEW_ERROR' }],
},
})
expect(screen.getByText(/unknown error/)).toBeInTheDocument()
})
it('handles an unexpected error type', () => {
setup({
errors: [{ errorCode: { error: 'bad config or something' } }],
props: {
errors: [{ errorCode: { error: 'bad config or something' } }],
},
})
expect(screen.getByText(/unknown error/)).toBeInTheDocument()
})
it('handles upload state error but no error code resolved as an known error', () => {
setup({
state: 'ERROR',
props: {
state: 'ERROR',
},
})
expect(screen.getByText(/unknown error/)).toBeInTheDocument()
})
it('handles upload state error but no errors returned', () => {
setup({
state: 'ERROR',
errors: [],
props: {
state: 'ERROR',
errors: [],
},
})
expect(screen.getByText(/unknown error/)).toBeInTheDocument()
})
it('If no state is provided and no errors received do not show an error', () => {
setup({
error: [],
props: {
error: [],
},
})
expect(screen.queryByText(/unknown error/)).not.toBeInTheDocument()
})
})

describe('rendering uploaded type of uploads', () => {
setup({ uploadType: 'UPLOADED' })
setup({ props: { uploadType: 'UPLOADED' } })
it('does not render carry-forward text', () => {
expect(screen.queryByText('carry-forward')).not.toBeInTheDocument()
})