-
Notifications
You must be signed in to change notification settings - Fork 15
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
{PROD4POD-1931} Add tests for poly-importer #1204
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "\u267B-PROD4POD-1930"
Changes from all commits
e0880a1
1ebcb7e
0393c1f
fb9c9f9
fc1ec4b
6e3e41b
e430caa
8a2b0af
fb307cd
0543893
2c65515
ec523e4
93a74b6
20d23bf
54c97d6
7894305
483b003
95d5309
1bd60a1
76910b8
b28b87c
15245f0
e991335
fac7da3
5ac68ff
e1979e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Importer } from "../src"; | ||
|
||
describe("Importer can't be instantiated ", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: What's with the trailing space here in the string? Also below. |
||
it("throws a TypeError", async () => { | ||
try { | ||
await new Importer().import({ zipFile: null, dataAccount: null }); | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(TypeError); | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { FileImportError, FileSelectionError, RefreshFilesError } from "../src"; | ||
|
||
const classData = [ | ||
[FileImportError, "import"], | ||
[FileSelectionError, "select"], | ||
[RefreshFilesError, "refresh"], | ||
]; | ||
|
||
describe("Errors have the right API ", () => { | ||
it("throw correctly their type errors", () => { | ||
classData.forEach(([testClass, testMsg]) => { | ||
const testCause = "test"; | ||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as this checks the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it checks that it's effectively closed for modification, as in the open/closed principle. I'll check anyway if it can be improved through encapsulation. And any way thanks for the suggestion, since this is still a draft. |
||
try { | ||
throw new testClass(testCause); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(testClass); | ||
expect(error.message).toMatch(new RegExp(testMsg)); | ||
expect(error.name).toBe(new testClass().constructor.name); | ||
expect(error.cause).toBe(testCause); | ||
} | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { polyProtocolRegex } from "@polypoly-eu/api"; | ||
import { MockPod } from "@polypoly-eu/api/dist/mock-pod"; | ||
import { FeatureFileStorage } from "../src"; | ||
|
||
describe("File storage ", () => { | ||
let fileStorage; | ||
beforeAll(() => { | ||
const pod = new MockPod(); | ||
fileStorage = new FeatureFileStorage(pod); | ||
}); | ||
it("when instantiated there are no files stored", () => { | ||
expect(fileStorage.files).toBeNull; | ||
}); | ||
}); | ||
|
||
describe("File storage", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Figure these two describe blocks could be merged, but not that important. |
||
let fileStorage; | ||
let fileUri; | ||
beforeAll(async () => { | ||
const pod = new MockPod(); | ||
fileUri = await pod.polyOut.importArchive("noRealFile.zip"); | ||
fileStorage = new FeatureFileStorage(pod); | ||
}); | ||
it("ignores non-existent archives", () => { | ||
expect(fileUri).toMatch(polyProtocolRegex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why export the regex and test it? I think it'd be better to leave it as an implementation detail and write a dedicated test for handling of invalid URLs. That regex is never used directly in production code, so no point testing it directly IMHO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, testing the fileUri against the protocol. The problem with leaving it as an implementation details is that we might end up having incompatible implementation details, and causing issues such as this one https://jira.polypoly.eu/browse/PROD4POD-1133 So it's not so much an implementation details as a single source of truth, because eventually we will be interchanging files between different implementations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a proposed API change - quite a different story. If we make that change we can test it, because the API would guarantee us to local paths. Right now it gives us internal URLs. You can test that it's a valid URL, but that's really as far as we should go. Testing that some internal regex used in the code matches the output makes little sense to me. What if the regex is wrong, and that causes the issue? I'd be OK with duplicating the regex in the tests, that way we at least don't have to expose implementation details... |
||
expect(fileStorage.files).toBeNull; | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||||||||||||||||
import { Telemetry } from "../src"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
describe("Telemetry measures performance ", () => { | ||||||||||||||||||||||||||
let telemetry; | ||||||||||||||||||||||||||
beforeAll(() => { | ||||||||||||||||||||||||||
telemetry = new Telemetry(); | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
it("Returns increasing elapsed time", () => { | ||||||||||||||||||||||||||
const oldTime = telemetry.elapsedTime(); | ||||||||||||||||||||||||||
expect(oldTime).toBeGreaterThan(0); | ||||||||||||||||||||||||||
expect(telemetry.elapsedTime()).toBeGreaterThan(oldTime); | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
Comment on lines
+9
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: just for its readability
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really... In this case I don't think readability would add much to it, just verbosity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mostly meant it for the test title - not just the separated var for newTime... |
||||||||||||||||||||||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ describe("Report metadata analysis", () => { | |
), | ||
], | ||
]); | ||
console.log(zipFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Forgotten? |
||
const { facebookAccount, analysisResult } = await runAnalysisForExport( | ||
ReportMetadataAnalysis, | ||
zipFile | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ export function createUUID(): string { | |
return uuidv4(); | ||
} | ||
|
||
const polyProtocol = "polypod://"; | ||
const polyProtocolRegex = new RegExp(`^${polyProtocol}`); | ||
export const polyProtocol = "polypod://"; | ||
export const polyProtocolRegex = new RegExp(`^${polyProtocol}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above - I'm not a fan of exposing things for test purposes, the ability to mock components not under test being the only exception. Otherwise, things should be as private as possible and tests should make an effort to test code paths through the public API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really for testing; maybe I should have factored out this change as I have done with the rest. Main intention here is to make the polyProtocol a single source for all the literals that are used all over. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just realised that you could just call isPolypodUri with no need to export these internals. That said, I'm still not sure why the unit tests for poly-import need to ensure that importArchive works as expected... They can't even, only in the test feature can we test API across platforms. The poly-import tests are for testing code in this library, nothing outside it. |
||
|
||
/** | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️