-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(file-manager): improve file manager (#609)
- Loading branch information
Showing
12 changed files
with
351 additions
and
70 deletions.
There are no files selected for viewing
182 changes: 182 additions & 0 deletions
182
components/serverless-files/__tests__/normalizeInputs.test.js
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,182 @@ | ||
const normalizeInputs = require("./../utils/normalizeInputs"); | ||
|
||
describe("normalizeInputs function test", () => { | ||
it("passing empty value should throw error", async () => { | ||
try { | ||
normalizeInputs(); | ||
} catch (e) { | ||
return; | ||
} | ||
|
||
try { | ||
normalizeInputs({}); | ||
} catch (e) { | ||
return; | ||
} | ||
|
||
throw new Error(`Error should've been thrown.`); | ||
}); | ||
|
||
it(`must throw an error if inputs is missing "region"`, async () => { | ||
try { | ||
normalizeInputs({}); | ||
} catch (e) { | ||
expect(e.message).toBe('Component "region" is missing.'); | ||
return; | ||
} | ||
throw new Error(`Error should've been thrown.`); | ||
}); | ||
|
||
it(`must throw an error if inputs is missing "bucket"`, async () => { | ||
try { | ||
normalizeInputs({ region: "test-123" }); | ||
} catch (e) { | ||
expect(e.message).toBe('Component "bucket" is missing.'); | ||
return; | ||
} | ||
throw new Error(`Error should've been thrown.`); | ||
}); | ||
|
||
it("passing old inputs structure should return new inputs structure with overrides applied correctly", async () => { | ||
const inputs = normalizeInputs({ | ||
region: "test-region", | ||
bucket: "test-bucket", | ||
memory: 1, | ||
timeout: 2, | ||
database: { | ||
one: 1, | ||
two: 2, | ||
three: 3 | ||
}, | ||
uploadMinFileSize: 3, | ||
uploadMaxFileSize: 4, | ||
env: { | ||
one: 1, | ||
two: 2, | ||
three: 3 | ||
}, | ||
webpackConfig: { | ||
four: 4, | ||
five: 5, | ||
six: 6 | ||
} | ||
}); | ||
|
||
expect(inputs).toEqual({ | ||
region: "test-region", | ||
bucket: "test-bucket", | ||
functions: { | ||
apolloService: { | ||
memory: 1, | ||
timeout: 2, | ||
database: { | ||
one: 1, | ||
two: 2, | ||
three: 3 | ||
}, | ||
uploadMinFileSize: 3, | ||
uploadMaxFileSize: 4, | ||
env: { | ||
one: 1, | ||
two: 2, | ||
three: 3 | ||
}, | ||
webpackConfig: { | ||
four: 4, | ||
five: 5, | ||
six: 6 | ||
} | ||
}, | ||
downloadFile: { | ||
memory: 512, | ||
timeout: 10, | ||
env: {} | ||
}, | ||
imageTransformer: { | ||
memory: 1024, | ||
timeout: 10, | ||
env: {} | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it("passing new inputs structure should return overrides successfully", async () => { | ||
const inputs = normalizeInputs({ | ||
name: "test-File", | ||
region: "test-region", | ||
bucket: "test-bucket", | ||
functions: { | ||
apolloService: { | ||
memory: 1, | ||
timeout: 2, | ||
database: { | ||
one: 1, | ||
two: 2, | ||
three: 3 | ||
}, | ||
uploadMinFileSize: 3, | ||
uploadMaxFileSize: 4, | ||
env: { | ||
one: 1, | ||
two: 2, | ||
three: 3 | ||
} | ||
}, | ||
downloadFile: { | ||
memory: 5, | ||
timeout: 6 | ||
}, | ||
imageTransformer: { | ||
memory: 7, | ||
timeout: 8 | ||
} | ||
}, | ||
webpackConfig: { | ||
four: 4, | ||
five: 5, | ||
six: 6 | ||
} | ||
}); | ||
|
||
expect(inputs).toEqual({ | ||
region: "test-region", | ||
bucket: "test-bucket", | ||
functions: { | ||
apolloService: { | ||
memory: 1, | ||
timeout: 2, | ||
database: { | ||
one: 1, | ||
two: 2, | ||
three: 3 | ||
}, | ||
uploadMinFileSize: 3, | ||
uploadMaxFileSize: 4, | ||
env: { | ||
one: 1, | ||
two: 2, | ||
three: 3 | ||
}, | ||
webpackConfig: null | ||
}, | ||
downloadFile: { | ||
memory: 5, | ||
timeout: 6, | ||
env: {} | ||
}, | ||
imageTransformer: { | ||
memory: 7, | ||
timeout: 8, | ||
env: {} | ||
} | ||
}, | ||
name: "test-File", | ||
webpackConfig: { | ||
four: 4, | ||
five: 5, | ||
six: 6 | ||
} | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.