|
1 | 1 | import { expect } from "chai";
|
| 2 | +import * as sinon from "sinon"; |
2 | 3 | import * as API from "./api-types";
|
3 | 4 | import { PrettyPrint } from "./pretty-print";
|
| 5 | +import { logger } from "../logger"; |
4 | 6 |
|
5 | 7 | const printer = new PrettyPrint();
|
6 | 8 |
|
@@ -92,3 +94,77 @@ describe("prettyStringArray", () => {
|
92 | 94 | expect(printer.prettyStringArray([])).to.equal("");
|
93 | 95 | });
|
94 | 96 | });
|
| 97 | + |
| 98 | +describe("prettyPrintDatabase", () => { |
| 99 | + let loggerInfoStub: sinon.SinonStub; |
| 100 | + |
| 101 | + const BASE_DATABASE: API.DatabaseResp = { |
| 102 | + name: "projects/my-project/databases/(default)", |
| 103 | + uid: "uid", |
| 104 | + createTime: "2020-01-01T00:00:00Z", |
| 105 | + updateTime: "2020-01-01T00:00:00Z", |
| 106 | + locationId: "us-central1", |
| 107 | + type: API.DatabaseType.FIRESTORE_NATIVE, |
| 108 | + concurrencyMode: "OPTIMISTIC", |
| 109 | + appEngineIntegrationMode: "ENABLED", |
| 110 | + keyPrefix: "prefix", |
| 111 | + deleteProtectionState: API.DatabaseDeleteProtectionState.DISABLED, |
| 112 | + pointInTimeRecoveryEnablement: API.PointInTimeRecoveryEnablement.DISABLED, |
| 113 | + etag: "etag", |
| 114 | + versionRetentionPeriod: "1h", |
| 115 | + earliestVersionTime: "2020-01-01T00:00:00Z", |
| 116 | + }; |
| 117 | + |
| 118 | + beforeEach(() => { |
| 119 | + loggerInfoStub = sinon.stub(logger, "info"); |
| 120 | + }); |
| 121 | + |
| 122 | + afterEach(() => { |
| 123 | + loggerInfoStub.restore(); |
| 124 | + }); |
| 125 | + |
| 126 | + it("should display STANDARD edition when databaseEdition is not provided", () => { |
| 127 | + const database: API.DatabaseResp = { ...BASE_DATABASE }; |
| 128 | + |
| 129 | + printer.prettyPrintDatabase(database); |
| 130 | + |
| 131 | + expect(loggerInfoStub.firstCall.args[0]).to.include("Edition"); |
| 132 | + expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD"); |
| 133 | + }); |
| 134 | + |
| 135 | + it("should display STANDARD edition when databaseEdition is UNSPECIFIED", () => { |
| 136 | + const database: API.DatabaseResp = { |
| 137 | + ...BASE_DATABASE, |
| 138 | + databaseEdition: API.DatabaseEdition.DATABASE_EDITION_UNSPECIFIED, |
| 139 | + }; |
| 140 | + |
| 141 | + printer.prettyPrintDatabase(database); |
| 142 | + |
| 143 | + expect(loggerInfoStub.firstCall.args[0]).to.include("Edition"); |
| 144 | + expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD"); |
| 145 | + }); |
| 146 | + |
| 147 | + it("should display ENTERPRISE edition when databaseEdition is ENTERPRISE", () => { |
| 148 | + const database: API.DatabaseResp = { |
| 149 | + ...BASE_DATABASE, |
| 150 | + databaseEdition: API.DatabaseEdition.ENTERPRISE, |
| 151 | + }; |
| 152 | + |
| 153 | + printer.prettyPrintDatabase(database); |
| 154 | + |
| 155 | + expect(loggerInfoStub.firstCall.args[0]).to.include("Edition"); |
| 156 | + expect(loggerInfoStub.firstCall.args[0]).to.include("ENTERPRISE"); |
| 157 | + }); |
| 158 | + |
| 159 | + it("should display STANDARD edition when databaseEdition is STANDARD", () => { |
| 160 | + const database: API.DatabaseResp = { |
| 161 | + ...BASE_DATABASE, |
| 162 | + databaseEdition: API.DatabaseEdition.STANDARD, |
| 163 | + }; |
| 164 | + |
| 165 | + printer.prettyPrintDatabase(database); |
| 166 | + |
| 167 | + expect(loggerInfoStub.firstCall.args[0]).to.include("Edition"); |
| 168 | + expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD"); |
| 169 | + }); |
| 170 | +}); |
0 commit comments