Files
outline/server/routes/api/imports/imports.test.ts
T
dependabot[bot] fc01deeefd chore(deps-dev): bump oxlint-tsgolint from 0.14.2 to 0.22.1 (#12320)
* chore(deps-dev): bump oxlint-tsgolint from 0.14.2 to 0.22.1

Bumps [oxlint-tsgolint](https://github.com/oxc-project/tsgolint) from 0.14.2 to 0.22.1.
- [Release notes](https://github.com/oxc-project/tsgolint/releases)
- [Commits](https://github.com/oxc-project/tsgolint/compare/v0.14.2...v0.22.1)

---
updated-dependencies:
- dependency-name: oxlint-tsgolint
  dependency-version: 0.22.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: Switch tsconfig to bundler resolution for tsgolint 0.22.1

oxlint-tsgolint 0.22.1 removed support for moduleResolution=node10
(the alias for "node"). Switch to "bundler" with resolvePackageJsonExports
disabled so packages whose exports field omits a types condition still
resolve. Update markdown-it type imports to sub-paths since the package's
.d.mts entry only re-exports a subset of named types.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: Resolve type-aware lint errors caught by tsgolint 0.22.1

oxlint-tsgolint 0.22.1 catches several await-thenable, no-floating-promises,
and no-meaningless-void-operator cases the prior 0.14.2 missed:

- Drop redundant inner `await` from Promise.all([await x, await y]) call sites
  so the array entries are real Promises rather than already-resolved values.
- Replace Promise.all wrappers around synchronous presenters (presentEvent,
  presentTemplate, presentPublicTeam) with plain map / direct calls.
- Wrap non-promise branches of ternaries inside Promise.all with
  Promise.resolve so the array remains thenable across both arms.
- Add `void` to the unawaited provider.connect() in the auth-failed retry
  chain, and remove `void` from the disconnect() call which returns void.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tom Moor <tom@getoutline.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 07:59:13 -04:00

310 lines
7.7 KiB
TypeScript

import type { NotionImportInput } from "@shared/schema";
import {
CollectionPermission,
ImportableIntegrationService,
ImportState,
IntegrationService,
IntegrationType,
} from "@shared/types";
import type { Import } from "@server/models";
import { Integration } from "@server/models";
import {
buildAdmin,
buildImport,
buildIntegration,
buildUser,
} from "@server/test/factories";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
describe("#imports.create", () => {
it("should create an import", async () => {
const admin = await buildAdmin();
const integration = await Integration.create<
Integration<IntegrationType.Import>
>({
service: IntegrationService.Notion,
type: IntegrationType.Import,
userId: admin.id,
teamId: admin.teamId,
settings: {
externalWorkspace: {
id: "testId",
name: "testWorkspaceName",
},
},
});
const input: NotionImportInput = [{ permission: undefined }];
const res = await server.post("/api/imports.create", {
body: {
integrationId: integration.id,
service: IntegrationService.Notion,
input,
token: admin.getJwtToken(),
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.id).toBeTruthy();
expect(body.data.name).toEqual("testWorkspaceName");
expect(body.data.state).toEqual(ImportState.Created);
expect(body.data.service).toEqual(IntegrationService.Notion);
expect(body.data.createdById).toEqual(admin.id);
});
it("should not allow more than one active import at a time", async () => {
const admin = await buildAdmin();
const integration = await buildIntegration({
userId: admin.id,
teamId: admin.teamId,
});
const input: NotionImportInput = [
{ permission: CollectionPermission.Read },
];
await buildImport({
createdById: admin.id,
teamId: admin.teamId,
integrationId: integration.id,
});
const res = await server.post("/api/imports.create", {
body: {
integrationId: integration.id,
service: ImportableIntegrationService.Notion,
input,
token: admin.getJwtToken(),
},
});
expect(res.status).toEqual(422);
});
it("should require authentication", async () => {
const res = await server.post("/api/imports.create");
expect(res.status).toEqual(401);
});
it("should require user to be admin", async () => {
const user = await buildUser();
const res = await server.post("/api/imports.create", {
body: {
token: user.getJwtToken(),
},
});
expect(res.status).toEqual(403);
});
});
describe("#imports.list", () => {
it("should list all imports", async () => {
const admin = await buildAdmin();
const [importOne, importTwo] = await Promise.all([
buildImport({
createdById: admin.id,
teamId: admin.teamId,
}),
buildImport({
createdById: admin.id,
teamId: admin.teamId,
}),
]);
const res = await server.post("/api/imports.list", {
body: {
service: IntegrationService.Notion,
token: admin.getJwtToken(),
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(2);
const importIds = body.data.map(
// oxlint-disable-next-line @typescript-eslint/no-explicit-any
(importModel: Import<any>) => importModel.id
);
expect(importIds).toContain(importOne.id);
expect(importIds).toContain(importTwo.id);
});
it("should require authentication", async () => {
const res = await server.post("/api/imports.list");
expect(res.status).toEqual(401);
});
it("should require user to be admin", async () => {
const user = await buildUser();
const res = await server.post("/api/imports.list", {
body: {
token: user.getJwtToken(),
},
});
expect(res.status).toEqual(403);
});
});
describe("#imports.info", () => {
it("should return the import", async () => {
const admin = await buildAdmin();
const importModel = await buildImport({
createdById: admin.id,
teamId: admin.teamId,
});
const res = await server.post("/api/imports.info", {
body: {
id: importModel.id,
token: admin.getJwtToken(),
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.id).toEqual(importModel.id);
});
it("should require authentication", async () => {
const res = await server.post("/api/imports.info");
expect(res.status).toEqual(401);
});
it("should require user to be admin", async () => {
const user = await buildUser();
const res = await server.post("/api/imports.info", {
body: {
token: user.getJwtToken(),
},
});
expect(res.status).toEqual(403);
});
});
describe("#imports.delete", () => {
it("should delete the import", async () => {
const admin = await buildAdmin();
const importModel = await buildImport({
state: ImportState.Completed,
createdById: admin.id,
teamId: admin.teamId,
});
const res = await server.post("/api/imports.delete", {
body: {
id: importModel.id,
token: admin.getJwtToken(),
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.success).toEqual(true);
});
it("should throw error when import is not in deletable state", async () => {
const admin = await buildAdmin();
const importModel = await buildImport({
state: ImportState.InProgress,
createdById: admin.id,
teamId: admin.teamId,
});
const res = await server.post("/api/imports.delete", {
body: {
id: importModel.id,
token: admin.getJwtToken(),
},
});
expect(res.status).toEqual(403);
});
it("should require authentication", async () => {
const res = await server.post("/api/imports.delete");
expect(res.status).toEqual(401);
});
it("should require user to be admin", async () => {
const user = await buildUser();
const res = await server.post("/api/imports.delete", {
body: {
token: user.getJwtToken(),
},
});
expect(res.status).toEqual(403);
});
});
describe("#imports.cancel", () => {
it("should cancel the import", async () => {
const admin = await buildAdmin();
const importModel = await buildImport({
createdById: admin.id,
teamId: admin.teamId,
});
const res = await server.post("/api/imports.cancel", {
body: {
id: importModel.id,
token: admin.getJwtToken(),
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.id).toEqual(importModel.id);
expect(body.data.state).toEqual(ImportState.Canceled);
});
it("should throw error when import is not in cancelable state", async () => {
const admin = await buildAdmin();
const importModel = await buildImport({
state: ImportState.Completed,
createdById: admin.id,
teamId: admin.teamId,
});
const res = await server.post("/api/imports.cancel", {
body: {
id: importModel.id,
token: admin.getJwtToken(),
},
});
expect(res.status).toEqual(403);
});
it("should require authentication", async () => {
const res = await server.post("/api/imports.cancel");
expect(res.status).toEqual(401);
});
it("should require user to be admin", async () => {
const user = await buildUser();
const res = await server.post("/api/imports.cancel", {
body: {
token: user.getJwtToken(),
},
});
expect(res.status).toEqual(403);
});
});