Skip to content

Commit f93a594

Browse files
author
brizental
committed
UploadAapter -> Uploader
1 parent e37ac8b commit f93a594

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

src/upload/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { GLEAN_VERSION } from "../constants";
66
import Glean from "glean";
77
import { Observer as PingsDatabaseObserver, PingInternalRepresentation } from "pings/database";
8-
import UploadAdapter from "upload/adapter";
8+
import Uploader from "upload/uploader";
99

1010
interface QueuedPing extends PingInternalRepresentation {
1111
identifier: string
@@ -154,7 +154,7 @@ class PingUploader implements PingsDatabaseObserver {
154154
}
155155

156156
const finalPing = this.preparePingForUpload(ping);
157-
const result = await UploadAdapter.post(
157+
const result = await Uploader.post(
158158
new URL(ping.path, Glean.serverEndpoint),
159159
finalPing.payload,
160160
finalPing.headers

src/upload/adapter/browser.ts renamed to src/upload/uploader/browser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import { UploadResult, UploadResultStatus } from "upload";
6-
import { UploadAdapter } from ".";
6+
import { Uploader } from ".";
77

8-
class BrowserUploadAdapter extends UploadAdapter {
8+
class BrowserUploader extends Uploader {
99
async post(url: URL, body: string, headers: Record<string, string> = {}): Promise<UploadResult> {
1010
const controller = new AbortController();
1111
const timeout = setTimeout(() => controller.abort(), this.defaultTimeout);
@@ -51,4 +51,4 @@ class BrowserUploadAdapter extends UploadAdapter {
5151
}
5252
}
5353

54-
export default new BrowserUploadAdapter();
54+
export default new BrowserUploader();

src/upload/adapter/index.ts renamed to src/upload/uploader/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { UploadResult, UploadResultStatus } from "upload";
77
/**
88
* Uploader interface, actualy uploading logic varies per platform.
99
*/
10-
export abstract class UploadAdapter {
10+
export abstract class Uploader {
1111
// The timeout, in seconds, to use for all operations with the server.
1212
protected defaultTimeout = 10_000;
1313

@@ -24,7 +24,7 @@ export abstract class UploadAdapter {
2424
}
2525

2626
// Default export for tests sake.
27-
class MockUploadAdapter extends UploadAdapter {
27+
class MockUploader extends Uploader {
2828
post(): Promise<UploadResult> {
2929
const result: UploadResult = {
3030
result: UploadResultStatus.Success,
@@ -34,4 +34,4 @@ class MockUploadAdapter extends UploadAdapter {
3434
}
3535
}
3636

37-
export default new MockUploadAdapter();
37+
export default new MockUploader();

tests/upload/index.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { v4 as UUIDv4 } from "uuid";
88

99
import Glean from "glean";
1010
import PingUploader, { UploadResultStatus } from "upload";
11-
import UploadAdapter from "upload/adapter";
11+
import Uploader from "upload/uploader";
1212

1313
const sandbox = sinon.createSandbox();
1414

@@ -97,7 +97,7 @@ describe("PingUploader", function() {
9797
});
9898

9999
it("if multiple pings are enqueued subsequently, we don't attempt to upload each ping more than once", async function () {
100-
const spy = sandbox.spy(UploadAdapter, "post");
100+
const spy = sandbox.spy(Uploader, "post");
101101
await fillUpPingsDatabase(100);
102102
await waitForGleanUploader();
103103
assert.strictEqual(spy.callCount, 100);
@@ -132,7 +132,7 @@ describe("PingUploader", function() {
132132

133133
it("correctly deletes pings when upload is unrecoverably unsuccesfull", async function() {
134134
// Always return unrecoverable failure response from upload attempt.
135-
sandbox.stub(UploadAdapter, "post").callsFake(() => Promise.resolve({
135+
sandbox.stub(Uploader, "post").callsFake(() => Promise.resolve({
136136
status: 400,
137137
result: UploadResultStatus.Success
138138
}));
@@ -145,7 +145,7 @@ describe("PingUploader", function() {
145145

146146
it("correctly re-enqueues pings when upload is recovarbly unsuccesfull", async function() {
147147
// Always return recoverable failure response from upload attempt.
148-
sandbox.stub(UploadAdapter, "post").callsFake(() => Promise.resolve({
148+
sandbox.stub(Uploader, "post").callsFake(() => Promise.resolve({
149149
status: 500,
150150
result: UploadResultStatus.Success
151151
}));
@@ -182,7 +182,7 @@ describe("PingUploader", function() {
182182

183183
it("maximum of recoverable errors is enforced", async function () {
184184
// Always return recoverable failure response from upload attempt.
185-
const stub = sandbox.stub(UploadAdapter, "post").callsFake(() => Promise.resolve({
185+
const stub = sandbox.stub(Uploader, "post").callsFake(() => Promise.resolve({
186186
status: 500,
187187
result: UploadResultStatus.Success
188188
}));

tests/upload/adapter.spec.ts renamed to tests/upload/uploader.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import assert from "assert";
77
import sinon from "sinon";
88

99
import { UploadResultStatus } from "upload";
10-
import BrowserUploadAdapter from "upload/adapter/browser";
10+
import BrowserUploader from "upload/uploader/browser";
1111
import { JSONObject } from "utils";
1212

1313
const sandbox = sinon.createSandbox();
@@ -54,7 +54,7 @@ function createResponse(status: number): Response {
5454
return new Response("", { status });
5555
}
5656

57-
describe("UploadAdapter/browser", function () {
57+
describe("Uploader/browser", function () {
5858
afterEach(async function () {
5959
sandbox.restore();
6060
});
@@ -64,15 +64,15 @@ describe("UploadAdapter/browser", function () {
6464
for (const [index, status] of [200, 400, 500].entries()) {
6565
stub.onCall(index).returns(Promise.resolve(createResponse(status)));
6666
assert.deepStrictEqual(
67-
await BrowserUploadAdapter.post(new URL("htpps://localhost:8080"), ""),
67+
await BrowserUploader.post(new URL("htpps://localhost:8080"), ""),
6868
{ status: status, result: UploadResultStatus.Success });
6969
}
7070
});
7171

7272
it("doesn't throw if upload action throws", async function () {
7373
sandbox.stub(global, "fetch").callsFake(() => Promise.reject());
7474
assert.deepStrictEqual(
75-
await BrowserUploadAdapter.post(new URL("htpps://localhost:8080"), ""),
75+
await BrowserUploader.post(new URL("htpps://localhost:8080"), ""),
7676
{ result: UploadResultStatus.RecoverableFailure }
7777
);
7878
});

0 commit comments

Comments
 (0)