瀏覽代碼

transloadit: Add tests for types.

Renée Kooi 6 年之前
父節點
當前提交
f31adbb1be
共有 3 個文件被更改,包括 72 次插入6 次删除
  1. 12 4
      packages/@uppy/transloadit/types/index.d.ts
  2. 53 0
      packages/@uppy/transloadit/types/transloadit-tests.ts
  3. 7 2
      tsconfig.json

+ 12 - 4
packages/@uppy/transloadit/types/index.d.ts

@@ -1,13 +1,21 @@
 import { Plugin, PluginOptions, Uppy, UppyFile } from '@uppy/core';
 
+export interface AssemblyParameters {
+  auth: { key: string };
+  template_id?: string;
+  steps?: { [step: string]: object };
+  notify_url?: string;
+  fields?: { [name: string]: number | string };
+}
+
 export interface AssemblyOptions {
-  params: object;
-  fields: object;
-  signature: string;
+  params: AssemblyParameters;
+  fields?: { [name: string]: number | string };
+  signature?: string;
 }
 
 export interface TransloaditOptions extends PluginOptions {
-  params: any;
+  params: AssemblyParameters;
   signature: string;
   service: string;
   waitForEncoding: boolean;

+ 53 - 0
packages/@uppy/transloadit/types/transloadit-tests.ts

@@ -0,0 +1,53 @@
+import Uppy, { UppyFile } from '@uppy/core';
+import Transloadit  from '../';
+
+{
+  const uppy = Uppy();
+  uppy.use(Transloadit, {
+    getAssemblyOptions(file) {
+      file // $ExpectType UppyFile
+    },
+    waitForEncoding: false,
+    waitForMetadata: true,
+    importFromUploadURLs: false,
+    params: {
+      auth: { key: 'abc' },
+      steps: {}
+    }
+  });
+}
+
+{
+  const uppy = Uppy();
+  // $ExpectError
+  uppy.use(Transloadit, { waitForEncoding: null });
+  // $ExpectError
+  uppy.use(Transloadit, { waitForMetadata: null });
+}
+
+{
+  const uppy = Uppy();
+  // $ExpectError
+  uppy.use(Transloadit, { params: {} });
+  // $ExpectError
+  uppy.use(Transloadit, { params: { auth: {} } });
+  // $ExpectError
+  uppy.use(Transloadit, {
+    params: {
+      auth: { key: null }
+    }
+  });
+  // $ExpectError
+  uppy.use(Transloadit, {
+    params: {
+      auth: { key: 'abc' },
+      steps: 'test'
+    }
+  });
+  uppy.use(Transloadit, {
+    params: {
+      auth: { key: 'abc' },
+      steps: { name: {} }
+    }
+  });
+}

+ 7 - 2
tsconfig.json

@@ -1,6 +1,5 @@
 {
   "compilerOptions": {
-    "noEmit": true,
     "target": "esnext",
     "module": "commonjs",
     "lib": [
@@ -16,5 +15,11 @@
     "allowSyntheticDefaultImports": true,
     "strictFunctionTypes": true,
     "forceConsistentCasingInFileNames": true
-  }
+  },
+  "include": [
+    "packages/*/types/index.d.ts",
+    "packages/*/types/*-tests.ts",
+    "packages/@uppy/*/types/index.d.ts",
+    "packages/@uppy/*/types/*-tests.ts",
+  ]
 }