Skip to content

Commit

Permalink
Merge pull request #20 from badsyntax/api-mock
Browse files Browse the repository at this point in the history
Add initial api mocks
  • Loading branch information
badsyntax authored Aug 6, 2020
2 parents 291170a + b8fcf19 commit 91e3a51
Show file tree
Hide file tree
Showing 81 changed files with 3,500 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name-template: '$NEXT_PATCH_VERSION'
tag-template: '$NEXT_PATCH_VERSION'
template: |
$CHANGES
53 changes: 46 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
name: Build
name: Build and Publish
on:
push:
release:
types: [published]
jobs:
validate:
name: Validate
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node 12.18.x
uses: actions/setup-node@v1
with:
node-version: 12.18.x
- name: Install dependencies
run: |
npm install
- name: Lint
run: |
npm run lint
- name: Build
run: |
cat << CONFIG > src/config/config.json
{
"hostname": "box.example.com",
"mockApi": true
}
CONFIG
npm run build
publish:
needs: [check]
name: Publish
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
npm install
- name: Build
run: |
cat << CONFIG > src/config/config.json
{
"hostname": "box.example.com",
"mockApi": true
}
CONFIG
PUBLIC_URL=/mailinabox-ui/ npm run build
- name: Publish
run: |
mv build .build
tag=${GITHUB_REF#refs/tags/}
git checkout gh-pages
rm -rf *
mv .build/* .
rm -rf .build
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "Add build for version $tag"
git push
13 changes: 13 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release Drafter
on:
push:
branches:
- master
jobs:
update-release-draft:
runs-on: ubuntu-latest
steps:
- name: Draft release
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
npm-debug.log*

# config files
/src/config/index.json
/src/config/config.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ An experimental SPA user interface for Mail-in-a-Box, using the following tools:
### Instructions

1. Clone the repo
2. Copy `src/config/index.example.json` to `src/config/index.json` and update the `hostname` field within `index.json` to point to your box
2. Copy `src/config/config.example.json` to `src/config/config.json` and update the `hostname` field within `index.json` to point to your box
3. From the root of the project:
1. Run `npm install`
2. Run `npm start`
Expand Down
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^3.1.4",
"fetch-mock": "^9.10.6",
"http-proxy-middleware": "^1.0.5",
"mailinabox-api": "^0.46.4",
"prettier": "^2.0.5",
Expand Down
17 changes: 17 additions & 0 deletions src/api/mockApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import fetchMock from 'fetch-mock';
import { mocks } from './mocks';

Object.keys(mocks).forEach((url) => {
const methods = mocks[url];
Object.keys(methods).forEach((method) => {
const data = mocks[url][method];
fetchMock.mock(
{
url,
method,
delay: 500,
},
data
);
});
});
3 changes: 3 additions & 0 deletions src/api/mocks/dns/data/addDnsCustomARecord.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"response": "updated DNS: example.com"
}
3 changes: 3 additions & 0 deletions src/api/mocks/dns/data/addDnsCustomRecord.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"response": "updated DNS: example.com"
}
3 changes: 3 additions & 0 deletions src/api/mocks/dns/data/addDnsSecondaryNameserver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"response": "updated DNS: example.com"
}
9 changes: 9 additions & 0 deletions src/api/mocks/dns/data/getDnsCustomARecordsForQName.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"response": [
{
"qname": "example.com",
"rtype": "MX",
"value": "10 example.com."
}
]
}
74 changes: 74 additions & 0 deletions src/api/mocks/dns/data/getDnsCustomRecords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"response": [
{
"qname": "example.com",
"rtype": "A",
"value": "11.12.13.14"
},
{
"qname": "example.com",
"rtype": "AAAA",
"value": "2a09:4fa:1c1c:e08a::2"
},
{
"qname": "example2.com",
"rtype": "A",
"value": "12.13.14.15"
},
{
"qname": "blog.example2.com",
"rtype": "A",
"value": "13.14.15.16"
},
{
"qname": "www.example3.com",
"rtype": "A",
"value": "13.14.15.16"
},
{
"qname": "www.example3.com",
"rtype": "AAAA",
"value": "2a11:8f8:1c1c:b688::1"
},
{
"qname": "blog.example3.com",
"rtype": "A",
"value": "13.14.15.16"
},
{
"qname": "blog.example3.com",
"rtype": "AAAA",
"value": "2a11:8f8:1c1c:b688::1"
},
{
"qname": "example4.com",
"rtype": "A",
"value": "13.14.15.16"
},
{
"qname": "example4.com",
"rtype": "AAAA",
"value": "2a11:8f8:1c1c:b688::1"
},
{
"qname": "shop.example4.com",
"rtype": "AAAA",
"value": "2a11:8f8:1c1c:b688::1"
},
{
"qname": "shop.example4.com",
"rtype": "A",
"value": "13.14.15.16"
},
{
"qname": "example5.com",
"rtype": "A",
"value": "13.14.15.16"
},
{
"qname": "example5.com",
"rtype": "AAAA",
"value": "2a11:8f8:1c1c:b688::1"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"response": [
{
"qname": "example.com",
"rtype": "MX",
"value": "10 example.com."
}
]
}
Loading

0 comments on commit 91e3a51

Please sign in to comment.