-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Directly in file creation so no need to update it later. Also ensure file name and file path are decoded URI to avoid encoded spaces (%20) or other encoded characters by the import lib
- Loading branch information
Showing
5 changed files
with
236 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
export const AndroidReceivedFileFixture = { | ||
contentUri: | ||
'content://com.android.providers.downloads.documents/document/foo%1A23', | ||
extension: 'pdf', | ||
fileName: '123_foo_bar_baz_45.67EUR.pdf', | ||
filePath: | ||
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf', | ||
mimeType: 'application/pdf', | ||
subject: null | ||
} | ||
export const AndroidReceivedFileFixture = [ | ||
{ | ||
contentUri: | ||
'content://com.android.providers.downloads.documents/document/foo%1A23', | ||
extension: 'pdf', | ||
fileName: '123_foo_bar_baz_45.67EUR.pdf', | ||
filePath: | ||
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf', | ||
mimeType: 'application/pdf', | ||
subject: null | ||
} | ||
] | ||
|
||
export const AndroidReceivedFileFixture2 = { | ||
contentUri: | ||
'content://com.android.providers.downloads.documents/document/foo%1A32', | ||
extension: 'pdf', | ||
fileName: '321_foo_bar_baz_45.67EUR.pdf', | ||
filePath: | ||
'/data/user/0/io.cozy.flagship.mobile/cache/321_foo_bar_baz_45.67EUR.pdf', | ||
mimeType: 'application/pdf', | ||
subject: null | ||
} | ||
export const AndroidReceivedFileFixtures = [ | ||
{ | ||
contentUri: | ||
'content://com.android.providers.downloads.documents/document/foo%1A23', | ||
extension: 'pdf', | ||
fileName: '123_foo_bar_baz_45.67EUR.pdf', | ||
filePath: | ||
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf', | ||
mimeType: 'application/pdf', | ||
subject: null | ||
}, | ||
{ | ||
contentUri: | ||
'content://com.android.providers.downloads.documents/document/foo%1A232', | ||
extension: 'pdf', | ||
fileName: '123_foo_bar_baz_452.67EUR.pdf', | ||
filePath: | ||
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR2.pdf', | ||
mimeType: 'application/pdf', | ||
subject: null | ||
} | ||
] |
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,35 @@ | ||
export const iOSReceivedFileFixture = [ | ||
{ | ||
contentUri: null, | ||
extension: 'pdf', | ||
fileName: 'Carte_Alan.pdf', | ||
filePath: | ||
'file:///Users/anc/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan.pdf', | ||
mimeType: '.pdf', | ||
text: null, | ||
weblink: null | ||
} | ||
] | ||
|
||
export const iOSReceivedFileFixtures = [ | ||
{ | ||
contentUri: null, | ||
extension: 'pdf', | ||
fileName: 'Carte_Alan.pdf', | ||
filePath: | ||
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan.pdf', | ||
mimeType: '.pdf', | ||
text: null, | ||
weblink: null | ||
}, | ||
{ | ||
contentUri: null, | ||
extension: 'pdf', | ||
fileName: 'Carte_Alan2.pdf', | ||
filePath: | ||
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan2.pdf', | ||
mimeType: '.pdf', | ||
text: null, | ||
weblink: null | ||
} | ||
] |
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
150 changes: 150 additions & 0 deletions
150
src/app/domain/osReceive/services/OsReceiveData.spec.ts
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,150 @@ | ||
import { _onReceiveFiles } from '/app/domain/osReceive/services/OsReceiveData' | ||
import { | ||
AndroidReceivedFileFixture, | ||
AndroidReceivedFileFixtures | ||
} from '/app/domain/osReceive/fixtures/AndroidReceivedFile' | ||
import { | ||
iOSReceivedFileFixture, | ||
iOSReceivedFileFixtures | ||
} from '/app/domain/osReceive/fixtures/iOSReceivedFile' | ||
import { OsReceiveFile } from '/app/domain/osReceive/models/OsReceiveState' | ||
|
||
describe('onReceiveFiles', () => { | ||
beforeAll(() => { | ||
jest.spyOn(console, 'log').mockImplementation(() => { | ||
// noop | ||
}) | ||
}) | ||
|
||
it('should process Android file correctly', () => { | ||
const result = _onReceiveFiles(AndroidReceivedFileFixture) | ||
|
||
const expected: OsReceiveFile[] = [ | ||
{ | ||
file: { | ||
contentUri: | ||
'content://com.android.providers.downloads.documents/document/foo%1A23', | ||
extension: 'pdf', | ||
fileName: '123_foo_bar_baz_45.67EUR.pdf', | ||
filePath: | ||
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf', | ||
fromFlagship: true, | ||
mimeType: 'application/pdf', | ||
subject: null | ||
}, | ||
name: '123_foo_bar_baz_45.67EUR.pdf', | ||
status: 0, | ||
type: 'application/pdf' | ||
} | ||
] | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('should process Android files correctly', () => { | ||
const result = _onReceiveFiles(AndroidReceivedFileFixtures) | ||
|
||
const expected: OsReceiveFile[] = [ | ||
{ | ||
file: { | ||
contentUri: | ||
'content://com.android.providers.downloads.documents/document/foo%1A23', | ||
extension: 'pdf', | ||
fileName: '123_foo_bar_baz_45.67EUR.pdf', | ||
filePath: | ||
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf', | ||
fromFlagship: true, | ||
mimeType: 'application/pdf', | ||
subject: null | ||
}, | ||
name: '123_foo_bar_baz_45.67EUR.pdf', | ||
status: 0, | ||
type: 'application/pdf' | ||
}, | ||
{ | ||
file: { | ||
contentUri: | ||
'content://com.android.providers.downloads.documents/document/foo%1A232', | ||
extension: 'pdf', | ||
fileName: '123_foo_bar_baz_452.67EUR.pdf', | ||
filePath: | ||
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR2.pdf', | ||
fromFlagship: true, | ||
mimeType: 'application/pdf', | ||
subject: null | ||
}, | ||
name: '123_foo_bar_baz_452.67EUR.pdf', | ||
status: 0, | ||
type: 'application/pdf' | ||
} | ||
] | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('should process iOS file correctly', () => { | ||
const result = _onReceiveFiles(iOSReceivedFileFixture) | ||
|
||
const expected: OsReceiveFile[] = [ | ||
{ | ||
file: { | ||
contentUri: null, | ||
extension: 'pdf', | ||
fileName: 'Carte_Alan.pdf', | ||
filePath: | ||
'file:///Users/anc/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan.pdf', | ||
fromFlagship: true, | ||
mimeType: 'application/pdf', | ||
text: null, | ||
weblink: null | ||
}, | ||
name: 'Carte_Alan.pdf', | ||
status: 0, | ||
type: 'application/pdf' | ||
} | ||
] | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('should process iOS files correctly', () => { | ||
const result = _onReceiveFiles(iOSReceivedFileFixtures) | ||
|
||
const expected: OsReceiveFile[] = [ | ||
{ | ||
file: { | ||
contentUri: null, | ||
extension: 'pdf', | ||
fileName: 'Carte_Alan.pdf', | ||
filePath: | ||
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan.pdf', | ||
fromFlagship: true, | ||
mimeType: 'application/pdf', | ||
text: null, | ||
weblink: null | ||
}, | ||
name: 'Carte_Alan.pdf', | ||
status: 0, | ||
type: 'application/pdf' | ||
}, | ||
{ | ||
file: { | ||
contentUri: null, | ||
extension: 'pdf', | ||
fileName: 'Carte_Alan2.pdf', | ||
filePath: | ||
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan2.pdf', | ||
fromFlagship: true, | ||
mimeType: 'application/pdf', | ||
text: null, | ||
weblink: null | ||
}, | ||
name: 'Carte_Alan2.pdf', | ||
status: 0, | ||
type: 'application/pdf' | ||
} | ||
] | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
}) |
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