-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2618 from cozy/feat/Add-export-data-page
Add export data page
- Loading branch information
Showing
24 changed files
with
1,075 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const DATE_FORMAT = 'YYYY-MM-DD' | ||
export const DATA_EXPORT_DIR_ID = 'io.cozy.files.root-dir' | ||
export const DATA_EXPORT_NAME = 'export-data-banks.csv' | ||
export const DATA_EXPORT_PATH = `/${DATA_EXPORT_NAME}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { JOBS_DOCTYPE } from 'src/doctypes' | ||
|
||
/** | ||
* Find export job in progress | ||
* | ||
* @param {CozyClient} client | ||
*/ | ||
export const isExportJobInProgress = async client => { | ||
const jobColl = client.collection(JOBS_DOCTYPE) | ||
// This method return all jobs queued or running state | ||
const { data: allJobsServiceQueuedOrRunning } = await jobColl.queued( | ||
'service' | ||
) | ||
|
||
return allJobsServiceQueuedOrRunning.some( | ||
job => | ||
job.attributes.message.slug === 'banks' && | ||
job.attributes.message.name === 'export' | ||
) | ||
} | ||
|
||
/** | ||
* Launch export job | ||
* | ||
* @param {CozyClient} client | ||
*/ | ||
export const launchExportJob = async client => { | ||
const exportJobInProgress = await isExportJobInProgress(client) | ||
|
||
if (!exportJobInProgress) { | ||
const jobColl = client.collection(JOBS_DOCTYPE) | ||
await jobColl.create('service', { slug: 'banks', name: 'export' }, {}, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { launchExportJob, isExportJobInProgress } from './helpers' | ||
|
||
describe('Export Job', () => { | ||
const makeJob = ({ name, slug, state }) => { | ||
return { | ||
type: 'io.cozy.jobs', | ||
attributes: { | ||
worker: 'service', | ||
message: { | ||
name, | ||
slug | ||
}, | ||
state | ||
} | ||
} | ||
} | ||
|
||
const setup = ({ | ||
mockQueued = jest.fn(), | ||
mockCreate = jest.fn(), | ||
mockDownload = jest.fn() | ||
} = {}) => { | ||
const client = { | ||
collection: jest.fn(() => ({ | ||
queued: mockQueued, | ||
create: mockCreate, | ||
download: mockDownload | ||
})) | ||
} | ||
return client | ||
} | ||
|
||
describe('launchExportJob', () => { | ||
it('should not create a new job if it already exists', async () => { | ||
const expected = [ | ||
makeJob({ name: 'export', slug: 'banks' }), | ||
makeJob({ name: 'otherName', slug: 'otherSlug' }) | ||
] | ||
const mockQueued = jest.fn(() => ({ data: expected })) | ||
const mockCreate = jest.fn(() => ({ data: expected })) | ||
const client = setup({ mockQueued, mockCreate }) | ||
|
||
await launchExportJob(client) | ||
|
||
expect(mockCreate).toBeCalledTimes(0) | ||
}) | ||
|
||
it("should create a new job if it doesn't already exist with the correct arguments", async () => { | ||
const expected = [ | ||
makeJob({ name: 'na', slug: 'na' }), | ||
makeJob({ name: 'otherName', slug: 'otherSlug' }) | ||
] | ||
const mockQueued = jest.fn(() => ({ data: expected })) | ||
const mockCreate = jest.fn(() => ({ data: expected })) | ||
const client = setup({ mockQueued, mockCreate }) | ||
|
||
await launchExportJob(client) | ||
|
||
expect(mockCreate).toBeCalledTimes(1) | ||
expect(mockCreate).toBeCalledWith( | ||
'service', | ||
{ slug: 'banks', name: 'export' }, | ||
{}, | ||
true | ||
) | ||
}) | ||
}) | ||
|
||
describe('isExportJobInProgress', () => { | ||
it('should return "false" if export job is not running or queued', async () => { | ||
const expected = [ | ||
makeJob({ name: 'na', slug: 'na' }), | ||
makeJob({ name: 'otherName', slug: 'otherSlug' }) | ||
] | ||
const mockQueued = jest.fn(() => ({ data: expected })) | ||
const client = setup({ mockQueued }) | ||
|
||
const res = await isExportJobInProgress(client) | ||
|
||
expect(res).toBe(false) | ||
}) | ||
|
||
it('should return "true" if export job is running or queued', async () => { | ||
const expected = [ | ||
makeJob({ name: 'export', slug: 'banks' }), | ||
makeJob({ name: 'otherName', slug: 'otherSlug' }) | ||
] | ||
const mockQueued = jest.fn(() => ({ data: expected })) | ||
const client = setup({ mockQueued }) | ||
|
||
const res = await isExportJobInProgress(client) | ||
|
||
expect(res).toBe(true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import cozyLogger from 'cozy-logger' | ||
export default cozyLogger.namespace('export') |
Oops, something went wrong.