Skip to content

Commit

Permalink
Move file store under a subdirectory.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed Jan 13, 2022
1 parent 2dbe91a commit 5bf7722
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions react-native/services/FileStore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class FileStore implements FileStoreInterface {
this.loading = true;

await FileSystem.makeDirectoryAsync(
`${FileSystem.documentDirectory}/${subdirectoryName}`,
`${FileSystem.documentDirectory}/react-native-app-helpers/file-store/${subdirectoryName}`,
{ intermediates: true }
);

Expand All @@ -38,7 +38,7 @@ export class FileStore implements FileStoreInterface {
} else if (this.subdirectoryName === null) {
throw new Error(`The file store is not loaded.`);
} else {
return `${FileSystem.documentDirectory}/${this.subdirectoryName}/${uuid}`;
return `${FileSystem.documentDirectory}/react-native-app-helpers/file-store/${this.subdirectoryName}/${uuid}`;
}
}

Expand All @@ -52,7 +52,7 @@ export class FileStore implements FileStoreInterface {
this.operationsInProgress++;

return await FileSystem.readDirectoryAsync(
`${FileSystem.documentDirectory}/${this.subdirectoryName}`
`${FileSystem.documentDirectory}/react-native-app-helpers/file-store/${this.subdirectoryName}`
);
} finally {
this.operationsInProgress--;
Expand Down
78 changes: 39 additions & 39 deletions react-native/services/FileStore/unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test(`creates a directory on load`, async () => {
expect(rejected).toBeFalsy();
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -69,7 +69,7 @@ test(`resolves load when creating the directory succeeds`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -121,7 +121,7 @@ test(`throws when loading while loading`, async () => {
expect(rejected).toBeFalsy();
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example First Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example First Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -156,7 +156,7 @@ test(`throws when loading while loaded`, async () => {
);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example First Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example First Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -219,7 +219,7 @@ test(`throws when generating a path while loading`, () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -254,7 +254,7 @@ test(`throws when generating a path once unloaded`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -285,11 +285,11 @@ test(`can generate paths`, async () => {
const actual = fileStore.generatePath(`5d515bcf-f201-463f-923f-7c6ab54e8ebf`);

expect(actual).toEqual(
`Example Document Directory/Example Subdirectory Name/5d515bcf-f201-463f-923f-7c6ab54e8ebf`
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name/5d515bcf-f201-463f-923f-7c6ab54e8ebf`
);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -354,7 +354,7 @@ test(`throws when listing while loading`, async () => {
);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -390,7 +390,7 @@ test(`throws when listing once unloaded`, async () => {
);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -433,12 +433,12 @@ test(`can list files`, async () => {
]);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).toBeCalledTimes(1);
expect(readDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`
);
expect(deleteAsync).not.toHaveBeenCalled();
expect(moveAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -501,7 +501,7 @@ test(`throws when deleting while loading`, async () => {
);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -537,7 +537,7 @@ test(`throws when deleting once unloaded`, async () => {
);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -588,13 +588,13 @@ test(`does not resolve the promise returned by deleting until deletion succeeds`
expect(rejected).toBeFalsy();
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
expect(deleteAsync).toBeCalledTimes(1);
expect(deleteAsync).toHaveBeenCalledWith(
`Example Document Directory/Example Subdirectory Name/1527b17e-08e7-49b5-9bff-09a1945f25f2`
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name/1527b17e-08e7-49b5-9bff-09a1945f25f2`
);
expect(moveAsync).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -625,13 +625,13 @@ test(`can delete files`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
expect(deleteAsync).toBeCalledTimes(1);
expect(deleteAsync).toHaveBeenCalledWith(
`Example Document Directory/Example Subdirectory Name/1527b17e-08e7-49b5-9bff-09a1945f25f2`
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name/1527b17e-08e7-49b5-9bff-09a1945f25f2`
);
expect(moveAsync).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -693,7 +693,7 @@ test(`throws when importing while loading`, async () => {
);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -729,7 +729,7 @@ test(`throws when importing once unloaded`, async () => {
);
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -780,7 +780,7 @@ test(`does not resolve the promise returned by importing until moving succeeds`,
expect(rejected).toBeFalsy();
expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand All @@ -789,7 +789,7 @@ test(`does not resolve the promise returned by importing until moving succeeds`,
expect(moveAsync).toHaveBeenCalledWith({
from: `Example File Uri`,
to: expect.stringMatching(
/^Example Document Directory\/Example Subdirectory Name\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
/^Example Document Directory\/react-native-app-helpers\/file-store\/Example Subdirectory Name\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
),
});
});
Expand Down Expand Up @@ -820,15 +820,15 @@ test(`can import files`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
expect(deleteAsync).not.toHaveBeenCalled();
expect(moveAsync).toBeCalledTimes(1);
expect(moveAsync).toHaveBeenCalledWith({
from: `Example File Uri`,
to: `Example Document Directory/Example Subdirectory Name/${uuid}`,
to: `Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name/${uuid}`,
});
});

Expand Down Expand Up @@ -887,7 +887,7 @@ test(`throws when unloading while loading`, () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -922,7 +922,7 @@ test(`throws when unloading once unloaded`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -963,12 +963,12 @@ test(`throws when unloading while listing files`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).toBeCalledTimes(1);
expect(readDirectoryAsync).toHaveBeenCalledWith(
`Example Document Directory/Example Subdirectory Name`
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`
);
expect(deleteAsync).not.toHaveBeenCalled();
expect(moveAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -1007,13 +1007,13 @@ test(`throws when unloading while deleting files`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
expect(deleteAsync).toBeCalledTimes(1);
expect(deleteAsync).toHaveBeenCalledWith(
`Example Document Directory/Example Subdirectory Name/1527b17e-08e7-49b5-9bff-09a1945f25f2`
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name/1527b17e-08e7-49b5-9bff-09a1945f25f2`
);
expect(moveAsync).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -1051,7 +1051,7 @@ test(`throws when unloading while importing files`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand All @@ -1060,7 +1060,7 @@ test(`throws when unloading while importing files`, async () => {
expect(moveAsync).toHaveBeenCalledWith({
from: `Example File Uri`,
to: expect.stringMatching(
/^Example Document Directory\/Example Subdirectory Name\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
/^Example Document Directory\/react-native-app-helpers\/file-store\/Example Subdirectory Name\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
),
});
});
Expand Down Expand Up @@ -1089,7 +1089,7 @@ test(`can unload before any file store operations occur`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -1128,12 +1128,12 @@ test(`can unload once listing files completes`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).toBeCalledTimes(1);
expect(readDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`
);
expect(deleteAsync).not.toHaveBeenCalled();
expect(moveAsync).not.toHaveBeenCalled();
Expand Down Expand Up @@ -1166,13 +1166,13 @@ test(`can unload once deleting files completes`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
expect(deleteAsync).toBeCalledTimes(1);
expect(deleteAsync).toHaveBeenCalledWith(
`Example Document Directory/Example Subdirectory Name/1527b17e-08e7-49b5-9bff-09a1945f25f2`
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name/1527b17e-08e7-49b5-9bff-09a1945f25f2`
);
expect(moveAsync).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -1204,14 +1204,14 @@ test(`can unload once importing files completes`, async () => {

expect(makeDirectoryAsync).toBeCalledTimes(1);
expect(makeDirectoryAsync).toBeCalledWith(
`Example Document Directory/Example Subdirectory Name`,
`Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name`,
{ intermediates: true }
);
expect(readDirectoryAsync).not.toHaveBeenCalled();
expect(deleteAsync).not.toHaveBeenCalled();
expect(moveAsync).toBeCalledTimes(1);
expect(moveAsync).toHaveBeenCalledWith({
from: `Example File Uri`,
to: `Example Document Directory/Example Subdirectory Name/${uuid}`,
to: `Example Document Directory/react-native-app-helpers/file-store/Example Subdirectory Name/${uuid}`,
});
});

0 comments on commit 5bf7722

Please sign in to comment.