-
Notifications
You must be signed in to change notification settings - Fork 990
/
Copy pathrollback.spec.ts
85 lines (70 loc) · 2.82 KB
/
rollback.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { expect } from "chai";
import { remoteConfigApiOrigin } from "../api";
import * as nock from "nock";
import { RemoteConfigTemplate } from "./interfaces";
import * as remoteconfig from "./rollback";
import { FirebaseError } from "../error";
const PROJECT_ID = "the-remoteconfig-test-project";
function createTemplate(versionNumber: string, date: string): RemoteConfigTemplate {
return {
parameterGroups: {},
version: {
updateUser: {
email: "jackiechu@google.com",
},
updateTime: date,
updateOrigin: "REST_API",
versionNumber: versionNumber,
},
conditions: [],
parameters: {},
etag: "123",
};
}
const latestTemplate: RemoteConfigTemplate = createTemplate("115", "2020-08-06T23:11:41.629Z");
const rollbackTemplate: RemoteConfigTemplate = createTemplate("114", "2020-08-07T23:11:41.629Z");
describe("RemoteConfig Rollback", () => {
afterEach(() => {
expect(nock.isDone()).to.equal(true, "all nock stubs should have been called");
nock.cleanAll();
});
describe("rollbackCurrentVersion", () => {
it("should return a rollback to the version number specified", async () => {
nock(remoteConfigApiOrigin())
.post(`/v1/projects/${PROJECT_ID}/remoteConfig:rollback?versionNumber=${115}`)
.reply(200, latestTemplate);
const RCtemplate = await remoteconfig.rollbackTemplate(PROJECT_ID, 115);
expect(RCtemplate).to.deep.equal(latestTemplate);
});
// TODO: there is no logic that this is testing. Is that intentional?
it.skip("should reject invalid rollback version number", async () => {
nock(remoteConfigApiOrigin())
.post(`/v1/projects/${PROJECT_ID}/remoteConfig:rollback?versionNumber=${1000}`)
.reply(200, latestTemplate);
const RCtemplate = await remoteconfig.rollbackTemplate(PROJECT_ID, 1000);
expect(RCtemplate).to.deep.equal(latestTemplate);
try {
await remoteconfig.rollbackTemplate(PROJECT_ID);
} catch (e: any) {
e;
}
});
// TODO: this also is not testing anything in the file. Is this intentional?
it.skip("should return a rollback to the previous version", async () => {
nock(remoteConfigApiOrigin())
.post(`/v1/projects/${PROJECT_ID}/remoteConfig:rollback?versionNumber=${undefined}`)
.reply(200, rollbackTemplate);
const RCtemplate = await remoteconfig.rollbackTemplate(PROJECT_ID);
expect(RCtemplate).to.deep.equal(rollbackTemplate);
});
it("should reject if the api call fails", async () => {
nock(remoteConfigApiOrigin())
.post(`/v1/projects/${PROJECT_ID}/remoteConfig:rollback?versionNumber=${4}`)
.reply(404, {});
await expect(remoteconfig.rollbackTemplate(PROJECT_ID, 4)).to.eventually.be.rejectedWith(
FirebaseError,
/Not Found/,
);
});
});
});