Skip to content

Commit 5d5001a

Browse files
committed
Making installations mudularization step1, build success
1 parent a67daa4 commit 5d5001a

34 files changed

+247
-283
lines changed

packages-exp/installations-exp/src/api/delete-installation.test.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ import { expect } from 'chai';
1919
import { SinonStub, stub } from 'sinon';
2020
import * as deleteInstallationRequestModule from '../functions/delete-installation-request';
2121
import { get, set } from '../helpers/idb-manager';
22-
import { AppConfig } from '../interfaces/app-config';
23-
import { FirebaseDependencies } from '../interfaces/firebase-dependencies';
22+
import {
23+
FirebaseInstallations,
24+
AppConfig
25+
} from '@firebase/installations-types-exp';
2426
import {
2527
InProgressInstallationEntry,
2628
RegisteredInstallationEntry,
2729
RequestStatus,
2830
UnregisteredInstallationEntry
2931
} from '../interfaces/installation-entry';
30-
import { getFakeDependencies } from '../testing/fake-generators';
32+
import { getFakeInstallations } from '../testing/fake-generators';
3133
import '../testing/setup';
3234
import { ErrorCode } from '../util/errors';
3335
import { sleep } from '../util/sleep';
@@ -36,14 +38,14 @@ import { deleteInstallation } from './delete-installation';
3638
const FID = 'children-of-the-damned';
3739

3840
describe('deleteInstallation', () => {
39-
let dependencies: FirebaseDependencies;
41+
let installations: FirebaseInstallations;
4042
let deleteInstallationRequestSpy: SinonStub<
4143
[AppConfig, RegisteredInstallationEntry],
4244
Promise<void>
4345
>;
4446

4547
beforeEach(() => {
46-
dependencies = getFakeDependencies();
48+
installations = getFakeInstallations();
4749

4850
deleteInstallationRequestSpy = stub(
4951
deleteInstallationRequestModule,
@@ -54,7 +56,7 @@ describe('deleteInstallation', () => {
5456
});
5557

5658
it('resolves without calling server API if there is no installation', async () => {
57-
await expect(deleteInstallation(dependencies)).to.be.fulfilled;
59+
await expect(deleteInstallation(installations)).to.be.fulfilled;
5860
expect(deleteInstallationRequestSpy).not.to.have.been.called;
5961
});
6062

@@ -63,11 +65,11 @@ describe('deleteInstallation', () => {
6365
registrationStatus: RequestStatus.NOT_STARTED,
6466
fid: FID
6567
};
66-
await set(dependencies.appConfig, entry);
68+
await set(installations.appConfig, entry);
6769

68-
await expect(deleteInstallation(dependencies)).to.be.fulfilled;
70+
await expect(deleteInstallation(installations)).to.be.fulfilled;
6971
expect(deleteInstallationRequestSpy).not.to.have.been.called;
70-
await expect(get(dependencies.appConfig)).to.eventually.be.undefined;
72+
await expect(get(installations.appConfig)).to.eventually.be.undefined;
7173
});
7274

7375
it('rejects without calling server API if the installation is pending', async () => {
@@ -76,9 +78,9 @@ describe('deleteInstallation', () => {
7678
registrationStatus: RequestStatus.IN_PROGRESS,
7779
registrationTime: Date.now() - 3 * 1000
7880
};
79-
await set(dependencies.appConfig, entry);
81+
await set(installations.appConfig, entry);
8082

81-
await expect(deleteInstallation(dependencies)).to.be.rejectedWith(
83+
await expect(deleteInstallation(installations)).to.be.rejectedWith(
8284
ErrorCode.DELETE_PENDING_REGISTRATION
8385
);
8486
expect(deleteInstallationRequestSpy).not.to.have.been.called;
@@ -96,10 +98,10 @@ describe('deleteInstallation', () => {
9698
creationTime: Date.now()
9799
}
98100
};
99-
await set(dependencies.appConfig, entry);
101+
await set(installations.appConfig, entry);
100102
stub(navigator, 'onLine').value(false);
101103

102-
await expect(deleteInstallation(dependencies)).to.be.rejectedWith(
104+
await expect(deleteInstallation(installations)).to.be.rejectedWith(
103105
ErrorCode.APP_OFFLINE
104106
);
105107
expect(deleteInstallationRequestSpy).not.to.have.been.called;
@@ -117,13 +119,13 @@ describe('deleteInstallation', () => {
117119
creationTime: Date.now()
118120
}
119121
};
120-
await set(dependencies.appConfig, entry);
122+
await set(installations.appConfig, entry);
121123

122-
await expect(deleteInstallation(dependencies)).to.be.fulfilled;
124+
await expect(deleteInstallation(installations)).to.be.fulfilled;
123125
expect(deleteInstallationRequestSpy).to.have.been.calledOnceWith(
124-
dependencies.appConfig,
126+
installations.appConfig,
125127
entry
126128
);
127-
await expect(get(dependencies.appConfig)).to.eventually.be.undefined;
129+
await expect(get(installations.appConfig)).to.eventually.be.undefined;
128130
});
129131
});

packages-exp/installations-exp/src/api/delete-installation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
import { deleteInstallationRequest } from '../functions/delete-installation-request';
1919
import { remove, update } from '../helpers/idb-manager';
20-
import { FirebaseDependencies } from '../interfaces/firebase-dependencies';
2120
import { RequestStatus } from '../interfaces/installation-entry';
2221
import { ERROR_FACTORY, ErrorCode } from '../util/errors';
22+
import { FirebaseInstallations } from '@firebase/installations-types-exp';
2323

2424
export async function deleteInstallation(
25-
dependencies: FirebaseDependencies
25+
installations: FirebaseInstallations
2626
): Promise<void> {
27-
const { appConfig } = dependencies;
27+
const { appConfig } = installations;
2828

2929
const entry = await update(appConfig, oldEntry => {
3030
if (oldEntry && oldEntry.registrationStatus === RequestStatus.NOT_STARTED) {

packages-exp/installations-exp/src/api/get-id.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,29 @@ import { expect } from 'chai';
1919
import { SinonStub, stub } from 'sinon';
2020
import * as getInstallationEntryModule from '../helpers/get-installation-entry';
2121
import * as refreshAuthTokenModule from '../helpers/refresh-auth-token';
22-
import { AppConfig } from '../interfaces/app-config';
23-
import { FirebaseDependencies } from '../interfaces/firebase-dependencies';
22+
import {
23+
FirebaseInstallations,
24+
AppConfig
25+
} from '@firebase/installations-types-exp';
2426
import {
2527
RegisteredInstallationEntry,
2628
RequestStatus
2729
} from '../interfaces/installation-entry';
28-
import { getFakeDependencies } from '../testing/fake-generators';
30+
import { getFakeInstallations } from '../testing/fake-generators';
2931
import '../testing/setup';
3032
import { getId } from './get-id';
3133

3234
const FID = 'disciples-of-the-watch';
3335

3436
describe('getId', () => {
35-
let dependencies: FirebaseDependencies;
37+
let installations: FirebaseInstallations;
3638
let getInstallationEntrySpy: SinonStub<
3739
[AppConfig],
3840
Promise<getInstallationEntryModule.InstallationEntryWithRegistrationPromise>
3941
>;
4042

4143
beforeEach(() => {
42-
dependencies = getFakeDependencies();
44+
installations = getFakeInstallations();
4345

4446
getInstallationEntrySpy = stub(
4547
getInstallationEntryModule,
@@ -56,7 +58,7 @@ describe('getId', () => {
5658
registrationPromise: Promise.resolve({} as RegisteredInstallationEntry)
5759
});
5860

59-
const fid = await getId(dependencies);
61+
const fid = await getId(installations);
6062
expect(fid).to.equal(FID);
6163
expect(getInstallationEntrySpy).to.be.calledOnce;
6264
});
@@ -83,7 +85,7 @@ describe('getId', () => {
8385
creationTime: Date.now()
8486
});
8587

86-
await getId(dependencies);
88+
await getId(installations);
8789
expect(refreshAuthTokenSpy).to.be.calledOnce;
8890
});
8991
});

packages-exp/installations-exp/src/api/get-id.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717

1818
import { getInstallationEntry } from '../helpers/get-installation-entry';
1919
import { refreshAuthToken } from '../helpers/refresh-auth-token';
20-
import { FirebaseDependencies } from '../interfaces/firebase-dependencies';
20+
import { FirebaseInstallations } from '@firebase/installations-types-exp';
2121

2222
export async function getId(
23-
dependencies: FirebaseDependencies
23+
installations: FirebaseInstallations
2424
): Promise<string> {
2525
const { installationEntry, registrationPromise } = await getInstallationEntry(
26-
dependencies.appConfig
26+
installations.appConfig
2727
);
2828

2929
if (registrationPromise) {
3030
registrationPromise.catch(console.error);
3131
} else {
3232
// If the installation is already registered, update the authentication
3333
// token if needed.
34-
refreshAuthToken(dependencies).catch(console.error);
34+
refreshAuthToken(installations).catch(console.error);
3535
}
3636

3737
return installationEntry.fid;

0 commit comments

Comments
 (0)