cloudflare/test/test.ts

105 lines
3.1 KiB
TypeScript
Raw Permalink Normal View History

2019-07-18 12:25:10 +00:00
// tslint:disable-next-line: no-implicit-dependencies
2024-06-15 15:08:03 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2019-07-18 12:25:10 +00:00
// tslint:disable-next-line: no-implicit-dependencies
2024-06-15 15:08:03 +00:00
import { Qenv } from '@push.rocks/qenv';
2019-07-18 12:25:10 +00:00
2022-09-27 17:23:20 +00:00
import * as cloudflare from '../ts/index.js';
2019-07-18 12:25:10 +00:00
2019-07-18 09:51:56 +00:00
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
2017-06-04 16:14:19 +00:00
2019-07-18 12:25:10 +00:00
const randomPrefix = Math.floor(Math.random() * 2000);
let testCloudflareAccount: cloudflare.CloudflareAccount;
tap.test('should create a valid instance of CloudflareAccount', async () => {
2024-06-15 15:08:03 +00:00
testCloudflareAccount = new cloudflare.CloudflareAccount(await testQenv.getEnvVarOnDemand('CF_KEY'));
});
tap.test('should preselect an account', async () => {
await testCloudflareAccount.preselectAccountByName('Sandbox Account');
})
2021-01-22 20:46:26 +00:00
tap.test('.listZones() -> should display an entire account', async (tools) => {
tools.timeout(600000);
const result = await testCloudflareAccount.convenience.listZones();
console.log(result);
// await tools.delayFor(10000);
});
tap.test(
'.getZoneId(domainName) -> should get an Cloudflare Id for a domain string',
2021-01-22 20:46:26 +00:00
async (tools) => {
tools.timeout(600000);
const id = await testCloudflareAccount.convenience.getZoneId('bleu.de');
console.log(`The account id for bleu.de is: ${id}`);
}
);
tap.test(
'.listRecords(domainName) -> should list all records for a specific Domain Name',
2021-01-22 20:46:26 +00:00
async (tools) => {
tools.timeout(600000);
2021-01-22 20:46:26 +00:00
await testCloudflareAccount.convenience.listRecords('bleu.de').then(async (responseArg) => {
console.log(responseArg);
});
}
);
2021-01-22 20:46:26 +00:00
tap.test('should create a valid record for a subdomain', async (tools) => {
tools.timeout(600000);
2020-02-10 11:26:13 +00:00
await testCloudflareAccount.convenience.createRecord(
`${randomPrefix}subdomain.bleu.de`,
'A',
2021-01-22 21:12:42 +00:00
'127.0.0.1',
120
2020-02-10 11:26:13 +00:00
);
});
2021-01-22 20:46:26 +00:00
tap.test('should get a record from Cloudflare', async (tools) => {
tools.timeout(600000);
2020-02-10 11:26:13 +00:00
await testCloudflareAccount.convenience
2020-02-09 17:36:29 +00:00
.getRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
2021-01-22 20:46:26 +00:00
.then((responseArg) => {
2020-02-09 17:36:29 +00:00
console.log(responseArg);
});
});
2021-01-22 20:46:26 +00:00
tap.test('should remove a subdomain record from Cloudflare', async (tools) => {
tools.timeout(600000);
2020-02-10 11:26:13 +00:00
await testCloudflareAccount.convenience
.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
2021-01-22 20:46:26 +00:00
.then(async (responseArg) => {
console.log(responseArg);
});
});
2017-06-04 15:29:19 +00:00
2017-06-05 17:14:26 +00:00
tap.test('.purge(some.domain) -> should purge everything', async () => {
await testCloudflareAccount.convenience.purgeZone('bleu.de');
});
2017-06-05 17:14:26 +00:00
tap.test('should list workers', async () => {
const workerArray = await testCloudflareAccount.workerManager.listWorkerScripts();
console.log(workerArray);
});
2019-07-18 12:25:10 +00:00
// WORKERS
tap.test('should create a worker', async () => {
2020-02-09 17:36:29 +00:00
const worker = await testCloudflareAccount.workerManager.createWorker(
'myawesomescript',
`addEventListener('fetch', event => { event.respondWith(fetch(event.request)) })`
);
2019-07-18 15:12:03 +00:00
await worker.setRoutes([
{
zoneName: 'bleu.de',
2021-01-22 20:46:26 +00:00
pattern: 'https://*bleu.de/hello',
},
2019-07-18 15:12:03 +00:00
]);
console.log(worker);
2019-07-18 12:25:10 +00:00
});
tap.test('should get workers again', async () => {
const workerArray = await testCloudflareAccount.workerManager.listWorkerScripts();
2019-07-18 15:12:03 +00:00
console.log(workerArray);
2019-07-18 12:25:10 +00:00
});
tap.start();