cloudflare/test/test.ts

89 lines
2.7 KiB
TypeScript
Raw Normal View History

2019-07-18 12:25:10 +00:00
// tslint:disable-next-line: no-implicit-dependencies
import { expect, tap } from '@pushrocks/tapbundle';
2019-07-18 12:25:10 +00:00
// tslint:disable-next-line: no-implicit-dependencies
import { Qenv } from '@pushrocks/qenv';
2019-07-18 12:25:10 +00:00
import cloudflare = require('../ts/index');
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 () => {
testCloudflareAccount = new cloudflare.CloudflareAccount({
email: testQenv.getEnvVarOnDemand('CF_EMAIL'),
key: testQenv.getEnvVarOnDemand('CF_KEY')
});
});
2019-07-18 12:25:10 +00:00
tap.skip.test('.listZones() -> should display an entire account', async tools => {
tools.timeout(600000);
2019-07-18 09:51:56 +00:00
const result = await testCloudflareAccount.listZones();
console.log(result);
});
tap.test(
'.getZoneId(domainName) -> should get an Cloudflare Id for a domain string',
async tools => {
tools.timeout(600000);
await testCloudflareAccount.getZoneId('bleu.de');
}
);
tap.test(
'.listRecords(domainName) -> should list all records for a specific Domain Name',
async tools => {
tools.timeout(600000);
await testCloudflareAccount.listRecords('bleu.de').then(async responseArg => {
console.log(responseArg);
});
}
);
tap.test('should create a valid record for a subdomain', async tools => {
tools.timeout(600000);
await testCloudflareAccount.createRecord(`${randomPrefix}subdomain.bleu.de`, 'A', '127.0.0.1');
});
tap.test('should get a record from Cloudflare', async tools => {
tools.timeout(600000);
2019-07-18 09:51:56 +00:00
await testCloudflareAccount.getRecord(`${randomPrefix}subdomain.bleu.de`, 'A').then(responseArg => {
console.log(responseArg);
});
});
tap.test('should remove a subdomain record from Cloudflare', async tools => {
tools.timeout(600000);
await testCloudflareAccount
.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
.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.purgeZone('bleu.de');
});
2017-06-05 17:14:26 +00:00
2019-07-18 12:25:10 +00:00
// WORKERS
tap.test('should create a worker', async () => {
2019-07-18 15:12:03 +00:00
const worker = await testCloudflareAccount.workerManager.createWorker('myawesomescript', `addEventListener('fetch', event => { event.respondWith(fetch(event.request)) })`);
await worker.setRoutes([
{
zoneName: 'bleu.de',
pattern: 'https://*bleu.de/hello'
}
]);
console.log(worker);
2019-07-18 12:25:10 +00:00
});
tap.test('should get workers', async () => {
2019-07-18 15:12:03 +00:00
const workerArray = await testCloudflareAccount.workerManager.listWorkers();
console.log(workerArray);
2019-07-18 12:25:10 +00:00
});
tap.start();