mengw15 commented on code in PR #7820: URL: https://github.com/apache/texera/pull/7820#discussion_r3866301213
########## frontend/src/app/common/service/warehouse/warehouse-actions.service.spec.ts: ########## @@ -0,0 +1,144 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { TestBed } from "@angular/core/testing"; +import { Subject, firstValueFrom, of, throwError } from "rxjs"; +import { NzModalService } from "ng-zorro-antd/modal"; +import { WarehouseActionsService } from "./warehouse-actions.service"; +import { WarehouseService } from "./warehouse.service"; +import { NotificationService } from "../notification/notification.service"; +import { DashboardWarehouse } from "../../type/warehouse"; + +describe("WarehouseActionsService", () => { + let service: WarehouseActionsService; + let modalService: { confirm: ReturnType<typeof vi.fn> }; + let warehouseService: { createWarehouse: ReturnType<typeof vi.fn>; deleteWarehouse: ReturnType<typeof vi.fn> }; + let notificationService: { error: ReturnType<typeof vi.fn>; success: ReturnType<typeof vi.fn> }; + + const warehouse: DashboardWarehouse = { + whid: 3, + name: "sales", + lakekeeperWarehouseName: "user-1-3", + flavor: "local", + createdAtMillis: 0, + ownerName: "Alice", + ownerAvatar: null, + }; + + beforeEach(() => { + modalService = { confirm: vi.fn() }; + warehouseService = { + createWarehouse: vi.fn().mockReturnValue(of(warehouse)), + deleteWarehouse: vi.fn().mockReturnValue(of(void 0)), + }; + notificationService = { error: vi.fn(), success: vi.fn() }; + + TestBed.configureTestingModule({ + providers: [ + WarehouseActionsService, + { provide: NzModalService, useValue: modalService }, + { provide: WarehouseService, useValue: warehouseService }, + { provide: NotificationService, useValue: notificationService }, + ], + }); + service = TestBed.inject(WarehouseActionsService); + }); + + it("creates through the warehouse service, so create and delete share one entry point", async () => { + const created = await firstValueFrom(service.create("mybucket")); + + expect(warehouseService.createWarehouse).toHaveBeenCalledWith("mybucket"); + expect(created).toEqual(warehouse); + }); + + it("asks for confirmation with the danger wording, without deleting yet", () => { + const onDeleted = vi.fn(); + + service.confirmAndDelete(warehouse, onDeleted); + + expect(modalService.confirm).toHaveBeenCalledTimes(1); + const config = modalService.confirm.mock.calls[0][0]; Review Comment: Refactored — the spec reaches the dialog through `confirmConfig()` / `clickDelete()` instead of repeating the mock path five times. ########## frontend/src/app/common/type/warehouse.ts: ########## @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * A per-user warehouse registration (#6870), as served by `GET /warehouse/status`. + * Mirrors the backend's `WarehouseResource.DashboardWarehouse`. + */ +export interface DashboardWarehouse { + whid: number; + /** The user-facing name, unique per user and free to change. */ + name: string; + /** The Lakekeeper catalog name (`user-<uid>-<whid>`), stable for life (#7753). */ + lakekeeperWarehouseName: string; + /** The storage backing the warehouse; matches the backend's user_warehouse_flavor enum. */ Review Comment: Fixed — `user_warehouse_flavor_enum` (sql/texera_ddl.sql:100). ########## frontend/src/app/common/type/warehouse.ts: ########## @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * A per-user warehouse registration (#6870), as served by `GET /warehouse/status`. Review Comment: Added — it's the response of `POST /warehouse` too. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
