Skip to content

Commit

Permalink
Merge pull request #10 from mantovanig/test/GM_integration-tests
Browse files Browse the repository at this point in the history
Integration Tests
  • Loading branch information
giacomotorricelli authored Feb 17, 2021
2 parents 0cbd4ba + 1c2597e commit c457481
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 327 deletions.
16 changes: 16 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/javascript-node/.devcontainer/base.Dockerfile

# [Choice] Node.js version: 14, 12, 10
ARG VARIANT="14-buster"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"
29 changes: 29 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/javascript-node
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 10, 12, 14
"args": { "VARIANT": "12" }
},

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.osx": "/bin/zsh"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
7 changes: 7 additions & 0 deletions __tests__/healthcheck.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('healthcheck', () => {
it('1 equals 1', () => {
expect(1).toBe(1);
});
});


109 changes: 109 additions & 0 deletions __tests__/mburger.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { createClient } from "../mburger";

const MBURGER_API_KEY = "7f24ae161f9070567363630870fb90d58ab67fcd";

describe("MBurger SDK", () => {
it("create a MBurger client", () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

expect(Boolean(client["getSection"])).toBeTruthy();
expect(Boolean(client["getBlocks"])).toBeTruthy();
expect(Boolean(client["getBlock"])).toBeTruthy();
});

it("Try to create a client without an api_key", () => {
expect(() => {
createClient();
}).toThrow();
});

it("Get a block", async () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

const res = await client.getBlock({
block_id: "1782",
});

expect(res).toBeInstanceOf(Array);
});

it("Get a block with a specific locale", async () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

const res = await client.getBlock({
block_id: "1782",

locale: "en",
});

// TODO(mantovanig): missing assertion on locale
expect(res).toBeInstanceOf(Array);
});

it("Get a error with an invalid block id", async () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

expect(async () => await client.getBlock({ block_id: "9999" })).rejects.toThrow(TypeError);
});

it("Get a section", async () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

const res = await client.getSection({
section_id: "321640",
});

expect(res.meta.id).toBe(321640);
});

it("Get a error with an invalid section id", async () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

expect(async () => await client.getSection({ section_id: "9999" })).rejects.toThrow(TypeError);
});

it("Get blocks array", async () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

const res = await client.getBlocks({
block_ids: [1782, 1787],
});

expect(res.Product.meta.id).toBe(1782);
expect(res.Categories.meta.id).toBe(1787);
})

it("Get a error calling getBlocks without block_ids", async () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

expect(async () => await client.getBlocks()).rejects.toThrow(TypeError);
})

it("Get a error calling getBlocks with id that does not exist", async () => {
const client = createClient({
api_key: MBURGER_API_KEY,
});

const res = await client.getBlocks({
block_ids: [9999],
});

expect(res).toStrictEqual({});
})
});
Empty file removed __tests__/section.test.js
Empty file.
Loading

0 comments on commit c457481

Please sign in to comment.