From 1c7d84ae94cd52821ed33d137608738bce6b8edd Mon Sep 17 00:00:00 2001 From: xinbenlv Date: Wed, 16 Oct 2024 19:10:52 -0700 Subject: [PATCH] update check to accept array input --- README.md | 2 +- epp/query.spec.ts | 23 +++++++++++++++++++---- epp/query.ts | 15 +++++++++------ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f73555b..ca01264 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/epp/query.spec.ts b/epp/query.spec.ts index e22760d..e364605 100644 --- a/epp/query.spec.ts +++ b/epp/query.spec.ts @@ -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 } + ]); }); }); }); diff --git a/epp/query.ts b/epp/query.ts index 8d1c558..1624245 100644 --- a/epp/query.ts +++ b/epp/query.ts @@ -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;