From b7fb398891edc7623d4adbfb6434e020db0c2d30 Mon Sep 17 00:00:00 2001 From: Benjamin VIELLARD Date: Fri, 22 Nov 2024 09:36:50 +0100 Subject: [PATCH] test: replace mockserver with wiremock --- .env.test | 3 +- docker-compose.test.yml | 10 +- mocks/imagga.json | 199 ------------------------------------ mocks/mappings/colors.json | 134 ++++++++++++++++++++++++ mocks/mappings/index.json | 9 ++ mocks/mappings/tags.json | 36 +++++++ mocks/mappings/uploads.json | 37 +++++++ mocks/mockserver.properties | 0 package.json | 4 +- pnpm-lock.yaml | 170 +++--------------------------- tests/extension.test.ts | 36 ++++--- 11 files changed, 258 insertions(+), 380 deletions(-) delete mode 100644 mocks/imagga.json create mode 100644 mocks/mappings/colors.json create mode 100644 mocks/mappings/index.json create mode 100644 mocks/mappings/tags.json create mode 100644 mocks/mappings/uploads.json delete mode 100644 mocks/mockserver.properties diff --git a/.env.test b/.env.test index 9818cd2..ca5270d 100644 --- a/.env.test +++ b/.env.test @@ -2,4 +2,5 @@ ADMIN_EMAIL="test@test.com" ADMIN_PASSWORD="test" ADMIN_TOKEN="test" PUBLIC_URL="http://127.0.0.1:8055" -IMAGGA_API="http://imagga:1080" +IMAGGA_API="http://imagga:8080" +IMAGGA_TAGS_ENABLE=true diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 99aa30b..836fb62 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -7,12 +7,8 @@ services: - ./:/directus/extensions/imagga env_file: ".env.test" imagga: - image: mockserver/mockserver:5.15.0 + image: wiremock/wiremock:latest ports: - - 1080:1080 - environment: - MOCKSERVER_PROPERTY_FILE: /mocks/mockserver.properties - MOCKSERVER_INITIALIZATION_JSON_PATH: /mocks/imagga.json - MOCKSERVER_WATCH_INITIALIZATION_JSON: "true" + - 8080:8080 volumes: - - ./mocks:/mocks + - ./mocks:/home/wiremock diff --git a/mocks/imagga.json b/mocks/imagga.json deleted file mode 100644 index ea2b659..0000000 --- a/mocks/imagga.json +++ /dev/null @@ -1,199 +0,0 @@ -[ - { - "httpRequest": { - "method": "POST", - "path": "/uploads" - }, - "httpResponse": { - "statusCode": 200, - "body": { - "result": { - "upload_id": "i05e132196706b94b1d85efb5f3SaM1j" - }, - "status": { - "text": "", - "type": "success" - } - } - } - }, - { - "httpRequest": { - "method": "GET", - "path": "/tags", - "query": { - "image_upload_id": "i05e132196706b94b1d85efb5f3SaM1j" - } - }, - "httpResponse": { - "statusCode": 200, - "body": { - "result": { - "tags": [ - { - "confidence": 61.4116096496582, - "tag": { - "en": "mountain" - } - }, - { - "confidence": 54.3507270812988, - "tag": { - "en": "landscape" - } - } - ] - }, - "status": { - "text": "", - "type": "success" - } - } - } - }, - { - "httpRequest": { - "method": "GET", - "path": "/colors", - "query": { - "image_upload_id": "i05e132196706b94b1d85efb5f3SaM1j" - } - }, - "httpResponse": { - "statusCode": 200, - "body": { - "result": { - "colors": { - "background_colors": [ - { - "b": 47, - "closest_palette_color": "light bronze", - "closest_palette_color_html_code": "#8c5e37", - "closest_palette_color_parent": "skin", - "closest_palette_distance": 1.70506228322597, - "g": 92, - "html_code": "#8c5c2f", - "percent": 48.0033950805664, - "r": 140 - }, - { - "b": 146, - "closest_palette_color": "cerulean", - "closest_palette_color_html_code": "#0074a8", - "closest_palette_color_parent": "blue", - "closest_palette_distance": 5.53350780052479, - "g": 116, - "html_code": "#467492", - "percent": 39.0454025268555, - "r": 70 - }, - { - "b": 30, - "closest_palette_color": "dark bronze", - "closest_palette_color_html_code": "#542e0c", - "closest_palette_color_parent": "skin", - "closest_palette_distance": 5.47689735887696, - "g": 48, - "html_code": "#4f301e", - "percent": 12.9512014389038, - "r": 79 - } - ], - "color_percent_threshold": 1.75, - "color_variance": 36, - "foreground_colors": [ - { - "b": 147, - "closest_palette_color": "larkspur", - "closest_palette_color_html_code": "#6e7e99", - "closest_palette_color_parent": "blue", - "closest_palette_distance": 8.60114706674971, - "g": 125, - "html_code": "#577d93", - "percent": 52.3429222106934, - "r": 87 - }, - { - "b": 145, - "closest_palette_color": "pewter", - "closest_palette_color_html_code": "#84898c", - "closest_palette_color_parent": "grey", - "closest_palette_distance": 1.75501013175431, - "g": 142, - "html_code": "#898e91", - "percent": 30.0293598175049, - "r": 137 - }, - { - "b": 42, - "closest_palette_color": "brownie", - "closest_palette_color_html_code": "#584039", - "closest_palette_color_parent": "brown", - "closest_palette_distance": 4.99189248709017, - "g": 58, - "html_code": "#593a2a", - "percent": 17.6277160644531, - "r": 89 - } - ], - "image_colors": [ - { - "b": 146, - "closest_palette_color": "cerulean", - "closest_palette_color_html_code": "#0074a8", - "closest_palette_color_parent": "blue", - "closest_palette_distance": 7.85085588656478, - "g": 121, - "html_code": "#547992", - "percent": 48.3686981201172, - "r": 84 - }, - { - "b": 46, - "closest_palette_color": "light bronze", - "closest_palette_color_html_code": "#8c5e37", - "closest_palette_color_parent": "skin", - "closest_palette_distance": 3.05634270891355, - "g": 86, - "html_code": "#83562e", - "percent": 47.9353446960449, - "r": 131 - }, - { - "b": 46, - "closest_palette_color": "navy blue", - "closest_palette_color_html_code": "#2b2e43", - "closest_palette_color_parent": "navy blue", - "closest_palette_distance": 6.62790662069936, - "g": 27, - "html_code": "#1f1b2e", - "percent": 3.60131478309631, - "r": 31 - } - ], - "object_percentage": 20.790994644165 - } - }, - "status": { - "text": "", - "type": "success" - } - } - } - }, - { - "httpRequest": { - "method": "DELETE", - "path": "/uploads/i05e132196706b94b1d85efb5f3SaM1j" - }, - "httpResponse": { - "statusCode": 200, - "body": { - "status": { - "text": "", - "type": "success" - } - } - } - } -] diff --git a/mocks/mappings/colors.json b/mocks/mappings/colors.json new file mode 100644 index 0000000..0ce6eb2 --- /dev/null +++ b/mocks/mappings/colors.json @@ -0,0 +1,134 @@ +{ + + "request": { + "method": "GET", + "url": "/colors", + "queryParameters": { + "image_upload_id": { + "equalTo": "i05e132196706b94b1d85efb5f3SaM1j" + } + } + }, + "response": { + "status": 200, + "jsonBody": { + "result": { + "colors": { + "background_colors": [ + { + "b": 47, + "closest_palette_color": "light bronze", + "closest_palette_color_html_code": "#8c5e37", + "closest_palette_color_parent": "skin", + "closest_palette_distance": 1.70506228322597, + "g": 92, + "html_code": "#8c5c2f", + "percent": 48.0033950805664, + "r": 140 + }, + { + "b": 146, + "closest_palette_color": "cerulean", + "closest_palette_color_html_code": "#0074a8", + "closest_palette_color_parent": "blue", + "closest_palette_distance": 5.53350780052479, + "g": 116, + "html_code": "#467492", + "percent": 39.0454025268555, + "r": 70 + }, + { + "b": 30, + "closest_palette_color": "dark bronze", + "closest_palette_color_html_code": "#542e0c", + "closest_palette_color_parent": "skin", + "closest_palette_distance": 5.47689735887696, + "g": 48, + "html_code": "#4f301e", + "percent": 12.9512014389038, + "r": 79 + } + ], + "color_percent_threshold": 1.75, + "color_variance": 36, + "foreground_colors": [ + { + "b": 147, + "closest_palette_color": "larkspur", + "closest_palette_color_html_code": "#6e7e99", + "closest_palette_color_parent": "blue", + "closest_palette_distance": 8.60114706674971, + "g": 125, + "html_code": "#577d93", + "percent": 52.3429222106934, + "r": 87 + }, + { + "b": 145, + "closest_palette_color": "pewter", + "closest_palette_color_html_code": "#84898c", + "closest_palette_color_parent": "grey", + "closest_palette_distance": 1.75501013175431, + "g": 142, + "html_code": "#898e91", + "percent": 30.0293598175049, + "r": 137 + }, + { + "b": 42, + "closest_palette_color": "brownie", + "closest_palette_color_html_code": "#584039", + "closest_palette_color_parent": "brown", + "closest_palette_distance": 4.99189248709017, + "g": 58, + "html_code": "#593a2a", + "percent": 17.6277160644531, + "r": 89 + } + ], + "image_colors": [ + { + "b": 146, + "closest_palette_color": "cerulean", + "closest_palette_color_html_code": "#0074a8", + "closest_palette_color_parent": "blue", + "closest_palette_distance": 7.85085588656478, + "g": 121, + "html_code": "#547992", + "percent": 48.3686981201172, + "r": 84 + }, + { + "b": 46, + "closest_palette_color": "light bronze", + "closest_palette_color_html_code": "#8c5e37", + "closest_palette_color_parent": "skin", + "closest_palette_distance": 3.05634270891355, + "g": 86, + "html_code": "#83562e", + "percent": 47.9353446960449, + "r": 131 + }, + { + "b": 46, + "closest_palette_color": "navy blue", + "closest_palette_color_html_code": "#2b2e43", + "closest_palette_color_parent": "navy blue", + "closest_palette_distance": 6.62790662069936, + "g": 27, + "html_code": "#1f1b2e", + "percent": 3.60131478309631, + "r": 31 + } + ], + "object_percentage": 20.790994644165 + } + }, + "status": { + "text": "", + "type": "success" + } + } + } + +} diff --git a/mocks/mappings/index.json b/mocks/mappings/index.json new file mode 100644 index 0000000..009194c --- /dev/null +++ b/mocks/mappings/index.json @@ -0,0 +1,9 @@ +{ + "request": { + "url": "/" + }, + "response": { + "status": 200, + "body": "OK" + } +} diff --git a/mocks/mappings/tags.json b/mocks/mappings/tags.json new file mode 100644 index 0000000..eeedfbd --- /dev/null +++ b/mocks/mappings/tags.json @@ -0,0 +1,36 @@ +{ + "request": { + "method": "GET", + "urlPath": "/tags", + "queryParameters": { + "image_upload_id": { + "equalTo": "i05e132196706b94b1d85efb5f3SaM1j" + } + } + }, + "response": { + "status": 200, + "jsonBody": { + "result": { + "tags": [ + { + "confidence": 61.4116096496582, + "tag": { + "en": "mountain" + } + }, + { + "confidence": 54.3507270812988, + "tag": { + "en": "landscape" + } + } + ] + }, + "status": { + "text": "", + "type": "success" + } + } + } +} diff --git a/mocks/mappings/uploads.json b/mocks/mappings/uploads.json new file mode 100644 index 0000000..037f08f --- /dev/null +++ b/mocks/mappings/uploads.json @@ -0,0 +1,37 @@ +{ + "mappings": [ + { + "request": { + "method": "POST", + "url": "/uploads" + }, + "response": { + "status": 200, + "jsonBody": { + "result": { + "upload_id": "i05e132196706b94b1d85efb5f3SaM1j" + }, + "status": { + "text": "", + "type": "success" + } + } + } + }, + { + "request": { + "method": "DELETE", + "url": "/uploads/i05e132196706b94b1d85efb5f3SaM1j" + }, + "response": { + "status": 200, + "jsonBody": { + "status": { + "text": "", + "type": "success" + } + } + } + } + ] +} diff --git a/mocks/mockserver.properties b/mocks/mockserver.properties deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index 4e74749..360473b 100644 --- a/package.json +++ b/package.json @@ -51,12 +51,12 @@ "dotenv": "16.4.5", "eslint": "9.15.0", "eslint-plugin-unicorn": "56.0.1", - "mockserver-client": "5.15.0", "rollup-plugin-node-externals": "7.1.3", "typescript": "5.6.3", "typescript-eslint": "8.15.0", "vitest": "2.1.5", - "wait-on": "8.0.1" + "wait-on": "8.0.1", + "wiremock-captain": "3.5.0" }, "peerDependencies": { "@directus/api": "23.1.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c5fcb6c..27e9528 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,9 +51,6 @@ importers: eslint-plugin-unicorn: specifier: 56.0.1 version: 56.0.1(eslint@9.15.0) - mockserver-client: - specifier: 5.15.0 - version: 5.15.0 rollup-plugin-node-externals: specifier: 7.1.3 version: 7.1.3(rollup@3.29.4) @@ -69,6 +66,9 @@ importers: wait-on: specifier: 8.0.1 version: 8.0.1 + wiremock-captain: + specifier: 3.5.0 + version: 3.5.0 packages: @@ -2370,9 +2370,6 @@ packages: resolution: {integrity: sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug==} engines: {node: '>=8'} - asap@2.0.6: - resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==} - asn1@0.2.6: resolution: {integrity: sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==} @@ -2473,9 +2470,6 @@ packages: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} - browser-or-node@2.1.1: - resolution: {integrity: sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==} - browserslist@4.24.2: resolution: {integrity: sha512-ZIc+Q62revdMcqC6aChtW4jz3My3klmCO1fEmINZY/8J3EpBg5/A/D0AKmBveUh6pgoeycoMkVMko84tuYS+Gg==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -2970,10 +2964,6 @@ packages: custom-error-instance@2.1.1: resolution: {integrity: sha512-p6JFxJc3M4OTD2li2qaHkDCw9SfMw82Ldr6OC9Je1aXiGfhx2W8p3GaoeaGrPJTUN9NirTM/KTxHWMUdR1rsUg==} - d@1.0.2: - resolution: {integrity: sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==} - engines: {node: '>=0.12'} - dataloader@1.4.0: resolution: {integrity: sha512-68s5jYdlvasItOJnCuI2Q9s4q98g0pCyL3HrcKJu8KNugUl8ahgmZYg38ysLTgQjjXX3H8CJLkAvWrclWfcalw==} @@ -3190,17 +3180,6 @@ packages: es-module-lexer@1.5.4: resolution: {integrity: sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==} - es5-ext@0.10.64: - resolution: {integrity: sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==} - engines: {node: '>=0.10'} - - es6-iterator@2.0.3: - resolution: {integrity: sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==} - - es6-symbol@3.1.4: - resolution: {integrity: sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==} - engines: {node: '>=0.12'} - esbuild@0.17.19: resolution: {integrity: sha512-XQ0jAPFkK/u3LcVRcvVHQcTIqD6E2H1fvZMA5dQPSOWb3suUbWbfbRf94pjc0bNzRYLfIrDRQXr7X+LHIm5oHw==} engines: {node: '>=12'} @@ -3268,10 +3247,6 @@ packages: resolution: {integrity: sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==} engines: {node: '>=6'} - esniff@2.0.1: - resolution: {integrity: sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==} - engines: {node: '>=0.10'} - espree@10.3.0: resolution: {integrity: sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -3307,9 +3282,6 @@ packages: resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==} engines: {node: '>= 0.6'} - event-emitter@0.3.5: - resolution: {integrity: sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==} - event-target-shim@5.0.1: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} @@ -3350,9 +3322,6 @@ packages: resolution: {integrity: sha512-pLdae7I6QqShF5PnNTCVn4hI91Dx0Grkn2+IAsMTgMIKuQVte2dN9PeGSSAME2FR8anOhVA62QDIUaWVfEXVLw==} engines: {node: '>= 0.10.0'} - ext@1.7.0: - resolution: {integrity: sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==} - extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} @@ -3870,9 +3839,6 @@ packages: resolution: {integrity: sha512-2AT6j+gXe/1ueqbW6fLZJiIw3F8iXGJtt0yDrZaBhAZEG1raiTxKWU+IPqMCzQAXOUCKdA4UDMgacKH25XG2Cw==} engines: {node: '>=4'} - is-typedarray@1.0.0: - resolution: {integrity: sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==} - is-unicode-supported@1.3.0: resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} engines: {node: '>=12'} @@ -4336,10 +4302,6 @@ packages: mnemonist@0.39.8: resolution: {integrity: sha512-vyWo2K3fjrUw8YeeZ1zF0fy6Mu59RHokURlld8ymdUPjMlD9EC9ov1/YPqTgqRvUN9nTr3Gqfz29LYAmu0PHPQ==} - mockserver-client@5.15.0: - resolution: {integrity: sha512-t0DiypyKH60cX1L9ubUMNnJz+XxmwTYHVdFePQMUNnrwBgERcA5WNqKyuttxRMf7P/WiWO3nWHNHSlPirIFEPw==} - engines: {node: '>= 0.8.0'} - mri@1.1.4: resolution: {integrity: sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w==} engines: {node: '>=4'} @@ -4401,9 +4363,6 @@ packages: resolution: {integrity: sha512-myRT3DiWPHqho5PrJaIRyaMv2kgYf0mUVgBNOYMuCH5Ki1yEiQaf/ZJuQ62nvpc44wL5WDbTX7yGJi1Neevw8w==} engines: {node: '>= 0.6'} - next-tick@1.1.0: - resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==} - node-abi@3.71.0: resolution: {integrity: sha512-SZ40vRiy/+wRTf21hxkkEjPJZpARzUMVcJoQse2EF8qkUWbbO2z7vd5oA/H6bVH6SZQ5STGcu0KRDS7biNRfxw==} engines: {node: '>=10'} @@ -4815,9 +4774,6 @@ packages: resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==} engines: {node: '>=4'} - pop-iterate@1.0.1: - resolution: {integrity: sha512-HRCx4+KJE30JhX84wBN4+vja9bNfysxg1y28l0DuJmkoaICiv2ZSilKddbS48pq50P8d2erAhqDLbp47yv3MbQ==} - postcss-calc@8.2.4: resolution: {integrity: sha512-SmWMSJmB8MRnnULldx0lQIyhSNvuDl9HfrZkaqqE/WHAhToYsAvDq+yAsA/kIyINDszOp3Rh0GFoNuH5Ypsm3Q==} peerDependencies: @@ -5095,13 +5051,6 @@ packages: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} - q@2.0.3: - resolution: {integrity: sha512-gv6vLGcmAOg96/fgo3d9tvA4dJNZL3fMyBqVRrGxQ+Q/o4k9QzbJ3NQF9cOO/71wRodoXhaPgphvMFU68qVAJQ==} - deprecated: |- - You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other. - - (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) - qs@6.11.0: resolution: {integrity: sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==} engines: {node: '>=0.6'} @@ -5728,12 +5677,6 @@ packages: resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} engines: {node: '>= 0.6'} - type@2.7.3: - resolution: {integrity: sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==} - - typedarray-to-buffer@3.1.5: - resolution: {integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==} - typedarray@0.0.7: resolution: {integrity: sha512-ueeb9YybpjhivjbHP2LdFDAjbS948fGEPj+ACAMs4xCMmh72OCOMQWBQKlaN4ZNQ04yfLSDLSx1tGRIoWimObQ==} @@ -5953,16 +5896,9 @@ packages: wcwidth@1.0.1: resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==} - weak-map@1.0.8: - resolution: {integrity: sha512-lNR9aAefbGPpHO7AEnY0hCFjz1eTkWCXYvkTRrTHs9qv8zJp+SkVYpzfLIFXQQiG3tVvbNFQgVg2bQS8YGgxyw==} - webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - websocket@1.0.35: - resolution: {integrity: sha512-/REy6amwPZl44DDzvRCkaI1q1bIiQB0mEFQLUrhz3z2EK91cp3n72rAjUlrTP0zV22HJIUOVHQGPxhFRjxjt+Q==} - engines: {node: '>=4.0.0'} - wellknown@0.5.0: resolution: {integrity: sha512-za5vTLuPF9nmrVOovYQwNEWE/PwJCM+yHMAj4xN1WWUvtq9OElsvKiPL0CR9rO8xhrYqL7NpI7IknqR8r6eYOg==} hasBin: true @@ -5987,6 +5923,10 @@ packages: resolution: {integrity: sha512-c9bZp7b5YtRj2wOe6dlj32MK+Bx/M/d+9VB2SHM1OtsUHR0aV0tdP6DWh/iMt0kWi1t5g1Iudu6hQRNd1A4PVA==} engines: {node: '>=18'} + wiremock-captain@3.5.0: + resolution: {integrity: sha512-2koJniQZYtc+rSy9kTzvfaxEYw1E+psyhM1PqJ26EzLZg4Gu2jwoj7dGNgriqQ3mi++ZHJPMmELpgHgG7RqoSw==} + engines: {node: '>=20.17.0', npm: '>=10.8.2'} + word-wrap@1.2.5: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} @@ -6040,10 +5980,6 @@ packages: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} - yaeti@0.0.6: - resolution: {integrity: sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==} - engines: {node: '>=0.10.32'} - yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} @@ -9213,8 +9149,6 @@ snapshots: arrify@2.0.1: {} - asap@2.0.6: {} - asn1@0.2.6: dependencies: safer-buffer: 2.1.2 @@ -9343,8 +9277,6 @@ snapshots: dependencies: fill-range: 7.1.1 - browser-or-node@2.1.1: {} - browserslist@4.24.2: dependencies: caniuse-lite: 1.0.30001680 @@ -9374,6 +9306,7 @@ snapshots: bufferutil@4.0.8: dependencies: node-gyp-build: 4.8.3 + optional: true builtin-modules@3.3.0: {} @@ -9702,11 +9635,6 @@ snapshots: custom-error-instance@2.1.1: {} - d@1.0.2: - dependencies: - es5-ext: 0.10.64 - type: 2.7.3 - dataloader@1.4.0: {} date-fns@4.1.0: {} @@ -9959,24 +9887,6 @@ snapshots: es-module-lexer@1.5.4: {} - es5-ext@0.10.64: - dependencies: - es6-iterator: 2.0.3 - es6-symbol: 3.1.4 - esniff: 2.0.1 - next-tick: 1.1.0 - - es6-iterator@2.0.3: - dependencies: - d: 1.0.2 - es5-ext: 0.10.64 - es6-symbol: 3.1.4 - - es6-symbol@3.1.4: - dependencies: - d: 1.0.2 - ext: 1.7.0 - esbuild@0.17.19: optionalDependencies: '@esbuild/android-arm': 0.17.19 @@ -10158,13 +10068,6 @@ snapshots: esm@3.2.25: {} - esniff@2.0.1: - dependencies: - d: 1.0.2 - es5-ext: 0.10.64 - event-emitter: 0.3.5 - type: 2.7.3 - espree@10.3.0: dependencies: acorn: 8.14.0 @@ -10193,11 +10096,6 @@ snapshots: etag@1.8.1: {} - event-emitter@0.3.5: - dependencies: - d: 1.0.2 - es5-ext: 0.10.64 - event-target-shim@5.0.1: {} eventemitter2@6.4.9: {} @@ -10274,10 +10172,6 @@ snapshots: transitivePeerDependencies: - supports-color - ext@1.7.0: - dependencies: - type: 2.7.3 - extend@3.0.2: {} extendable-error@0.1.7: {} @@ -10825,8 +10719,6 @@ snapshots: dependencies: better-path-resolve: 1.0.0 - is-typedarray@1.0.0: {} - is-unicode-supported@1.3.0: {} is-unicode-supported@2.1.0: {} @@ -11277,14 +11169,6 @@ snapshots: dependencies: obliterator: 2.0.4 - mockserver-client@5.15.0: - dependencies: - browser-or-node: 2.1.1 - q: 2.0.3 - websocket: 1.0.35 - transitivePeerDependencies: - - supports-color - mri@1.1.4: {} mri@1.2.0: {} @@ -11339,8 +11223,6 @@ snapshots: negotiator@0.6.4: optional: true - next-tick@1.1.0: {} - node-abi@3.71.0: dependencies: semver: 7.6.3 @@ -11848,8 +11730,6 @@ snapshots: pluralize@8.0.0: {} - pop-iterate@1.0.1: {} - postcss-calc@8.2.4(postcss@8.4.49): dependencies: postcss: 8.4.49 @@ -12111,12 +11991,6 @@ snapshots: punycode@2.3.1: {} - q@2.0.3: - dependencies: - asap: 2.0.6 - pop-iterate: 1.0.1 - weak-map: 1.0.8 - qs@6.11.0: dependencies: side-channel: 1.0.6 @@ -12908,12 +12782,6 @@ snapshots: media-typer: 0.3.0 mime-types: 2.1.35 - type@2.7.3: {} - - typedarray-to-buffer@3.1.5: - dependencies: - is-typedarray: 1.0.0 - typedarray@0.0.7: {} typescript-eslint@8.15.0(eslint@9.15.0)(typescript@5.6.3): @@ -12977,6 +12845,7 @@ snapshots: utf-8-validate@5.0.10: dependencies: node-gyp-build: 4.8.3 + optional: true util-deprecate@1.0.2: {} @@ -13112,21 +12981,8 @@ snapshots: dependencies: defaults: 1.0.4 - weak-map@1.0.8: {} - webidl-conversions@3.0.1: {} - websocket@1.0.35: - dependencies: - bufferutil: 4.0.8 - debug: 2.6.9 - es5-ext: 0.10.64 - typedarray-to-buffer: 3.1.5 - utf-8-validate: 5.0.10 - yaeti: 0.0.6 - transitivePeerDependencies: - - supports-color - wellknown@0.5.0: dependencies: concat-stream: 1.5.2 @@ -13155,6 +13011,12 @@ snapshots: dependencies: string-width: 7.2.0 + wiremock-captain@3.5.0: + dependencies: + axios: 1.7.7 + transitivePeerDependencies: + - debug + word-wrap@1.2.5: {} wrap-ansi@6.2.0: @@ -13202,8 +13064,6 @@ snapshots: xtend@4.0.2: optional: true - yaeti@0.0.6: {} - yallist@4.0.0: {} yallist@5.0.0: {} diff --git a/tests/extension.test.ts b/tests/extension.test.ts index 30ce7db..2657b67 100644 --- a/tests/extension.test.ts +++ b/tests/extension.test.ts @@ -1,43 +1,47 @@ import { describe, it, expect } from 'vitest' -import { createDirectus, rest, staticToken, readExtensions, uploadFiles, readFile } from "@directus/sdk"; +import { createDirectus, rest, staticToken, readExtensions, uploadFiles, readFile } from '@directus/sdk' import { name } from '../package.json' import { readFile as readFileFs } from 'node:fs/promises' -import { mockServerClient } from 'mockserver-client'; +import { WireMock } from 'wiremock-captain' describe('extension', () => { - const client = createDirectus(process.env.PUBLIC_URL as string) + // directus client + const directus = createDirectus(process.env.PUBLIC_URL as string) .with(rest()) .with(staticToken(process.env.ADMIN_TOKEN as string)) - const mockClient = mockServerClient('localhost', 1080) + // imagga mock server + const mock = new WireMock('http://127.0.0.1:8080') it('register correctly in directus', async () => { - const extensions = await client.request(readExtensions()) + const extensions = await directus.request(readExtensions()) expect(extensions).toBeDefined() expect(extensions.map(extension => extension.schema?.name)).toContain(name) }) - /* - it('triggers when image is uploaded', async () => { + it('tags image with imagga api', async () => { + await mock.clearAllExceptDefault() + + // upload image const data = new FormData() const paris = await readFileFs(`${import.meta.dirname}/paris.jpeg`) data.append('file', new Blob([paris], { type: 'image/jpeg' })) + const upload = await directus.request(uploadFiles(data)) - const files = await client.request(uploadFiles(data)) - expect(files).toBeDefined() + expect(upload.id).toBeDefined() - console.log(files) + // need to wait await new Promise(resolve => setTimeout(resolve, 1000)) - const mockTags = await mockClient.verify({ path: '/uploads' }); + const apiUploads = await mock.getRequestsForAPI('POST', '/uploads') + expect(apiUploads).toHaveLength(1) - const file = await client.request(readFile(files.id)) + // check if image is tagged with api results + const file = await directus.request(readFile(upload.id)) expect(file).toBeDefined() - - console.log(file) + expect(file.tags).toEqual(['mountain', 'landscape']) }, { - timeout: 100_000 + timeout: 10_000, }) - */ })