Skip to content

Commit af89d2a

Browse files
authored
Merge pull request #11 from GeoffSelby/next
V1.0.0
2 parents 129b71e + 0c44a75 commit af89d2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4157
-4828
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22

33
node_js:
4-
- '8'
4+
- '12.19.0'
55

66
cache:
77
directories:
@@ -14,4 +14,4 @@ install:
1414
- npm install
1515

1616
script:
17-
- npm test
17+
- npm test

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Forge JavaScript SDK
1+
# Laravel Forge JavaScript SDK
22

3-
<p>
4-
<a href="https://travis-ci.org/GeoffSelby/nevexo-forge-javascript-sdk"><img src="https://travis-ci.com/GeoffSelby/nevexo-forge-javascript-sdk.svg?branch=master" alt="Build Status"></a>
5-
</p>
3+
![Travis (.com)](https://img.shields.io/travis/com/GeoffSelby/laravel-forge-javascript-sdk?&style=for-the-badge)
4+
![npm](https://img.shields.io/npm/v/@geoffcodesthings/forge-js?&style=for-the-badge)
5+
![NPM](https://img.shields.io/npm/l/@geoffcodesthings/forge-js?style=for-the-badge)
66

7-
A complete, promise-based Javascript SDK for the Laravel Forge API
7+
A complete, asynchronous Javascript SDK for the Laravel Forge API
88

99
## Installation
1010

1111
With yarn (_recommended_):
1212

1313
```bash
14-
yarn add nevexo-forge-js
14+
yarn add @geoffcodesthings/forge-js
1515
```
1616

1717
With npm:
1818

1919
```bash
20-
npm install nevexo-forge-js
20+
npm install @geoffcodesthings/forge-js
2121
```
2222

2323
## Basic Usage
2424

2525
```js
26-
import Forge from 'nevexo-forge-js';
26+
import Forge from '@geoffcodesthings/forge-js';
2727

2828
// Instantiate the SDK
2929
const forge = new Forge('API_TOKEN_HERE');
@@ -37,11 +37,9 @@ try {
3737
}
3838
```
3939

40-
> The SDK utilizes native ES6 promises so you should use async/await to handle the resolved promise. You can, of course, use `.then()` and `.catch()` if you prefer.
41-
4240
## Documentation
4341

44-
Full documentation coming soon. Until then, please see the tests for more detailed usage.
42+
Full documentation can be found [here](https://laravel-forge-js-sdk.netlify.app).
4543

4644
## License
4745

__tests__/backups.test.js

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
const {
2+
setupFetchStub,
3+
expectToHaveBeenCalledWith,
4+
} = require('./stub/fetchStub');
5+
const Forge = require('../lib/Forge');
6+
7+
beforeAll(() => {
8+
require('cross-fetch/polyfill');
9+
jest.spyOn(window, 'fetch');
10+
});
11+
12+
afterEach(() => {
13+
global.fetch.mockReset();
14+
});
15+
16+
test('it creates a backup config', async () => {
17+
setupFetchStub();
18+
19+
const payload = {
20+
provider: 'spaces',
21+
credentials: {
22+
endpoint: 'https://my-endpoint.com',
23+
region: 'region-key',
24+
bucket: 'bucket-name',
25+
access_key: '',
26+
secret_key: '',
27+
},
28+
frequency: {
29+
type: 'weekly',
30+
time: '12:30',
31+
day: 1,
32+
},
33+
directory: 'backups/server/db',
34+
35+
retention: 7,
36+
databases: [24],
37+
};
38+
39+
const forge = new Forge('API_TOKEN');
40+
await forge.backups.createConfig(1, payload);
41+
42+
expectToHaveBeenCalledWith('/servers/1/backup-configs', 'POST', payload);
43+
44+
expect(window.fetch).toHaveBeenCalledTimes(1);
45+
});
46+
47+
test('it lists all backup configs', async () => {
48+
setupFetchStub();
49+
50+
const forge = new Forge('API_TOKEN');
51+
await forge.backups.listConfigs(1);
52+
53+
expectToHaveBeenCalledWith('/servers/1/backup-configs', 'GET');
54+
55+
expect(window.fetch).toHaveBeenCalledTimes(1);
56+
});
57+
58+
test('it gets a single backup config', async () => {
59+
setupFetchStub();
60+
61+
const forge = new Forge('API_TOKEN');
62+
await forge.backups.getConfig(1, 1);
63+
64+
expectToHaveBeenCalledWith('/servers/1/backup-configs/1', 'GET');
65+
66+
expect(window.fetch).toHaveBeenCalledTimes(1);
67+
});
68+
69+
test('it updates a given backup config', async () => {
70+
setupFetchStub();
71+
72+
const payload = {
73+
provider: 'spaces',
74+
credentials: {
75+
endpoint: 'https://my-endpoint.com',
76+
region: 'region-key',
77+
bucket: 'bucket-name',
78+
access_key: '',
79+
secret_key: '',
80+
},
81+
frequency: {
82+
type: 'weekly',
83+
time: '12:30',
84+
day: 1,
85+
},
86+
directory: 'backups/server/db',
87+
88+
retention: 7,
89+
databases: [24],
90+
};
91+
92+
const forge = new Forge('API_TOKEN');
93+
await forge.backups.updateConfig(1, 1, payload);
94+
95+
expectToHaveBeenCalledWith('/servers/1/backup-configs/1', 'POST', payload);
96+
97+
expect(window.fetch).toHaveBeenCalledTimes(1);
98+
});
99+
100+
test('it deletes a given backup config', async () => {
101+
setupFetchStub();
102+
103+
const forge = new Forge('API_TOKEN');
104+
await forge.backups.deleteConfig(1, 1);
105+
106+
expectToHaveBeenCalledWith('/servers/1/backup-configs/1', 'DELETE');
107+
108+
expect(window.fetch).toHaveBeenCalledTimes(1);
109+
});
110+
111+
test('it runs a given backup config', async () => {
112+
setupFetchStub();
113+
114+
const forge = new Forge('API_TOKEN');
115+
await forge.backups.runConfig(1, 1);
116+
117+
expectToHaveBeenCalledWith('/servers/1/backup-configs/1', 'POST');
118+
119+
expect(window.fetch).toHaveBeenCalledTimes(1);
120+
});
121+
122+
test('it restores a backup', async () => {
123+
setupFetchStub();
124+
125+
const payload = {
126+
database: 7,
127+
};
128+
129+
const forge = new Forge('API_TOKEN');
130+
await forge.backups.restore(1, 1, 1, payload);
131+
132+
expectToHaveBeenCalledWith(
133+
'/servers/1/backup-configs/1/backups/1',
134+
'POST',
135+
payload,
136+
);
137+
138+
expect(window.fetch).toHaveBeenCalledTimes(1);
139+
});
140+
141+
test('it deletes a backup', async () => {
142+
setupFetchStub();
143+
144+
const forge = new Forge('API_TOKEN');
145+
await forge.backups.delete(1, 1, 1);
146+
147+
expectToHaveBeenCalledWith('/servers/1/backup-configs/1/backups/1', 'DELETE');
148+
149+
expect(window.fetch).toHaveBeenCalledTimes(1);
150+
});

__tests__/config.test.js

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,66 @@
1-
import moxios from 'moxios';
2-
import Forge from '../lib/Forge';
1+
const {
2+
setupFetchStub,
3+
expectToHaveBeenCalledWith,
4+
} = require('./stub/fetchStub');
5+
const Forge = require('../lib/Forge');
36

4-
beforeEach(() => {
5-
moxios.install();
7+
beforeAll(() => {
8+
require('cross-fetch/polyfill');
9+
jest.spyOn(window, 'fetch');
610
});
711

812
afterEach(() => {
9-
moxios.uninstall();
13+
global.fetch.mockReset();
1014
});
1115

1216
test('it gets a given sites Nginx config', async () => {
13-
moxios.stubRequest('https://forge.laravel.com/api/v1/servers/1/sites/1/nginx', {
14-
status: 200,
15-
});
17+
setupFetchStub();
1618

1719
const forge = new Forge('API_TOKEN');
18-
const config = await forge.config.getNginx(1, 1);
20+
await forge.config.getNginx(1, 1);
1921

20-
expect(config.status).toEqual(200);
22+
expectToHaveBeenCalledWith('/servers/1/sites/1/nginx', 'GET');
23+
24+
expect(window.fetch).toHaveBeenCalledTimes(1);
2125
});
2226

2327
test('it updates a given Nginx config', async () => {
24-
moxios.stubRequest('https://forge.laravel.com/api/v1/servers/1/sites/1/nginx', {
25-
status: 200,
26-
});
28+
setupFetchStub();
2729

28-
const forge = new Forge('API_TOKEN');
29-
const config = await forge.config.updateNginx(1, 1, {
30+
const payload = {
3031
content: 'CONTENT',
31-
});
32+
};
33+
34+
const forge = new Forge('API_TOKEN');
35+
await forge.config.updateNginx(1, 1, payload);
36+
37+
expectToHaveBeenCalledWith('/servers/1/sites/1/nginx', 'POST', payload);
3238

33-
expect(config.status).toEqual(200);
39+
expect(window.fetch).toHaveBeenCalledTimes(1);
3440
});
3541

3642
test('it gets a given sites .env file', async () => {
37-
moxios.stubRequest('https://forge.laravel.com/api/v1/servers/1/sites/1/env', {
38-
status: 200,
39-
});
43+
setupFetchStub();
4044

4145
const forge = new Forge('API_TOKEN');
42-
const env = await forge.config.getEnv(1, 1);
46+
await forge.config.getEnv(1, 1);
4347

44-
expect(env.status).toEqual(200);
48+
expectToHaveBeenCalledWith('/servers/1/sites/1/env', 'GET');
49+
50+
expect(window.fetch).toHaveBeenCalledTimes(1);
4551
});
4652

4753
test('it updates a given .env file', async () => {
48-
moxios.stubRequest('https://forge.laravel.com/api/v1/servers/1/sites/1/env', {
49-
status: 200,
50-
});
54+
setupFetchStub();
5155

52-
const forge = new Forge('API_TOKEN');
53-
const env = await forge.config.updateEnv(1, 1, {
56+
const payload = {
5457
content: 'CONTENT',
55-
});
58+
};
59+
60+
const forge = new Forge('API_TOKEN');
61+
await forge.config.updateEnv(1, 1, payload);
62+
63+
expectToHaveBeenCalledWith('/servers/1/sites/1/env', 'POST', payload);
5664

57-
expect(env.status).toEqual(200);
65+
expect(window.fetch).toHaveBeenCalledTimes(1);
5866
});

__tests__/credentials.test.js

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
1-
import moxios from 'moxios';
2-
import Forge from '../lib/Forge';
1+
const {
2+
setupFetchStub,
3+
expectToHaveBeenCalledWith,
4+
} = require('./stub/fetchStub');
5+
const Forge = require('../lib/Forge');
36

4-
beforeEach(() => {
5-
moxios.install();
7+
beforeAll(() => {
8+
require('cross-fetch/polyfill');
9+
jest.spyOn(window, 'fetch');
610
});
711

812
afterEach(() => {
9-
moxios.uninstall();
13+
global.fetch.mockReset();
1014
});
1115

1216
test('it lists credentials', async () => {
13-
moxios.stubRequest('https://forge.laravel.com/api/v1/credentials', {
14-
response: {
15-
credentials: [
16-
{
17-
id: 1,
18-
type: 'ocean2',
19-
name: 'Personal',
20-
},
21-
],
22-
},
23-
});
17+
setupFetchStub();
2418

2519
const forge = new Forge('API_TOKEN');
26-
const credentials = await forge.credentials.list();
20+
await forge.credentials.list();
2721

28-
expect(credentials.data).toEqual({
29-
credentials: [
30-
{
31-
id: 1,
32-
type: 'ocean2',
33-
name: 'Personal',
34-
},
35-
],
36-
});
37-
});
22+
expectToHaveBeenCalledWith('/credentials', 'GET');
23+
24+
expect(window.fetch).toHaveBeenCalledTimes(1);
25+
});

0 commit comments

Comments
 (0)