diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dc41622..ceaa659 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,6 +28,12 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: npm ci - - run: npm run build --if-present + - name: Install dfx + run: | + echo y | DFX_VERSION=$DFX_VERSION bash -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + - name: Start dfx + run: | + dfx cache install + dfx start --background + - run: npm run setup - run: npm test diff --git a/backend/Backend.mo b/backend/Backend.mo index 73131af..43d903d 100644 --- a/backend/Backend.mo +++ b/backend/Backend.mo @@ -7,7 +7,7 @@ import HttpParser "mo:http-parser.mo"; import Types "./Types"; import Utils "./Utils"; -shared ({ caller = installer }) actor class Backend() { +actor class Backend() { type Request = HttpParser.ParsedHttpRequest; type HttpRequest = HttpParser.HttpRequest; type HttpResponse = HttpParser.HttpResponse; diff --git a/backend/test/Backend.test.mo b/backend/test/Backend.test.mo new file mode 100644 index 0000000..5c06e9c --- /dev/null +++ b/backend/test/Backend.test.mo @@ -0,0 +1,24 @@ +import Debug "mo:base/Debug"; +import Text "mo:base/Text"; + +import { Backend } "../Backend"; + +let backend = await Backend(); + +let cases = [ + ("/services/oembed?format=xml&url=https%3A%2F%2Fembed.smartcontracts.org%2Fabcdef&maxheight=800&lines=5", "1.0Embed Motokohttps://embed.motoko.orgrich800285<iframe src="https://embed.smartcontracts.org/abcdef" width="800" height="285" style="border:0" />"), +]; + +for ((url, expected) in cases.vals()) { + Debug.print(url); + let request = { + method = "GET"; + headers = []; + url; + body = "" : Blob; + }; + let received = (await backend.http_request(request)).body; + Debug.print(debug_show Text.decodeUtf8(received)); + assert received == Text.encodeUtf8(expected); + Debug.print(""); +}; diff --git a/package.json b/package.json index 5eecfa5..2afed10 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,10 @@ "frontend": "vite --port 3000", "backend": "mo-dev --generate --deploy -y", "build": "vite build", - "test": "vitest run", - "test:watch": "vitest", + "test": "run-s test:frontend test:backend", + "test:frontend": "vitest run", + "test:backend": "mo-test", + "test:watch": "run-p vitest mo-test", "sources": "mops sources", "prepare": "husky install", "precommit": "lint-staged"