Skip to content

Commit

Permalink
update check to accept array input
Browse files Browse the repository at this point in the history
  • Loading branch information
xinbenlv committed Oct 17, 2024
1 parent 737895f commit 1c7d84a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A typescript nodejs implementation of the EPP protocol.

## List of RFCs supported
## List of RFCs to be supported
### Core RFCs
- RFC 5730 - Extensible Provisioning Protocol (EPP) (Obsoletes RFC 3730)
This is the core EPP specification.
Expand Down
23 changes: 19 additions & 4 deletions epp/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,30 @@ describe('Query', () => {
describe('check', () => {
it('should return available true when object is not in storage', async () => {
const eppObject = new EppDomain("example.com");
const result = await query.check(eppObject);
expect(result).toEqual({ available: true });
const result = await query.check([eppObject]);
expect(result).toEqual([{ available: true }]);
});

it('should return available false with reason when object is in storage', async () => {
const eppObject = new EppDomain("example.com" );
await storage.set(eppObject.getKey(), eppObject);
const result = await query.check(eppObject);
expect(result).toEqual({ available: false, reason: 'In use' });
const result = await query.check([eppObject]);
expect(result).toEqual([{ available: false, reason: 'In use' }]);
});

it('should return available and unavailable when object is in storage', async () => {
const com = new EppDomain("example.com");
const net = new EppDomain("example.net");
const org = new EppDomain("example.org");

await storage.set(net.getKey(), net);

const result = await query.check([com, net, org]);
expect(result).toEqual([
{ available: true },
{ available: false, reason: 'In use' },
{ available: true }
]);
});
});
});
15 changes: 9 additions & 6 deletions epp/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ export class Query {
constructor(storage: Storage) {
this.storage = storage;
}
async check(o:EppObject): Promise<{ available: boolean, reason?: string }> {
const key = o.getKey();
if (await this.storage.get(key)) {
return { available: false, reason: "In use" };
}
return { available: true };
async check(objs:EppObject[]): Promise<{ available: boolean, reason?: string }[]> {
const results = await Promise.all(objs.map(async (o) => {
const key = o.getKey();
if (await this.storage.get(key)) {
return { available: false, reason: "In use" };
}
return { available: true };
}));
return results;
}
// info(): void;
// poll(): void;
Expand Down

0 comments on commit 1c7d84a

Please sign in to comment.