Skip to content

Commit

Permalink
chore: kickstart domain-check repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Kawacrepe committed Jul 19, 2022
1 parent 3dae0a8 commit 69826b3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ $ yarn add @nodesecure/domain-check
## Usage example

```js
import { main as domainCheck } from '@nodesecure/domain-check';
import { whois, resolveMxRecords } from '@nodesecure/domain-check';

const myDomain = 'bar.com';
const myDomain = 'google.com';

const domainInformations = await domainCheck(myDomain);
const domainExpirationDate = await whois(myDomain);
const mxRecords = await resolveMxRecords(myDomain);
```

## Contributors ✨
Expand Down
18 changes: 4 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { whois } from "./domainExpirationDate.js";
import { resolveMxRecords } from "./unregisteredMxRecords.js";

export async function main(domain) {
if (!domain) {
throw new Error("Domain is required");
}
export {
whois,
resolveMxRecords
};

const domainExpirationDate = await whois(domain);
const mxRecordsUnregistered = await resolveMxRecords(domain);

return {
domainExpirationDate,
mxRecordsUnregistered
};
}

main().catch((err) => console.error(err));
7 changes: 5 additions & 2 deletions src/unregisteredMxRecords.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dns from "dns/promises";
import dns from "node:dns/promises";

export async function resolveMxRecords(domain) {
const mxRecords = await dns.resolveMx(domain)
Expand All @@ -7,7 +7,10 @@ export async function resolveMxRecords(domain) {
: err.message));

if (mxRecords instanceof Error) {
return mxRecords.message;
return {
error: mxRecords.message,
context: mxRecords
};
}

return mxRecords.map(({ exchange }) => exchange);
Expand Down
41 changes: 39 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
// Import Third-party Dependencies
import test from "tape";

test("should pass", (t) => {
t.pass();
// Import Internal Dependencies
import { whois, resolveMxRecords } from "../src/index.js";

// MX OK
test("Given a valid domain, this test should pass", async(t) => {
// Given
const domain = "google.com";

// When
const mxRecords = await resolveMxRecords(domain);

// Then
t.equal(mxRecords[0], "smtp.google.com");
t.end();
});

// MX KO
test("Given an invalid domain, this test should not pass", async(t) => {
// Given
const domain = "aaa";

// When
const mxRecords = await resolveMxRecords(domain);

// Then
t.equal(mxRecords.error, `queryMx ENODATA ${domain}`);
t.end();
});

// Socket
test("Given a valid domain, this test should pass", async(t) => {
// Given
const domain = "google.com";

// When
const domainExpirationDate = await whois(domain);

// Then
t.isNot(domainExpirationDate, "");
t.end();
});

0 comments on commit 69826b3

Please sign in to comment.