11import { expect , describe , it , vi } from 'vitest'
2- import { DstackClient } from '../index'
2+ import { DstackClient , TappdClient } from '../index'
33
44describe ( 'DstackClient' , ( ) => {
5- it ( 'should able to derive key' , async ( ) => {
6- const client = new DstackClient ( )
5+ it ( 'should able to derive key in TappdClient ' , async ( ) => {
6+ const client = new TappdClient ( )
77 const result = await client . deriveKey ( '/' , 'test' )
88 expect ( result ) . toHaveProperty ( 'key' )
99 expect ( result ) . toHaveProperty ( 'certificate_chain' )
1010 } )
1111
12+ it ( 'should throws error in DstackClient' , async ( ) => {
13+ const client = new DstackClient ( )
14+ await expect ( ( ) => client . deriveKey ( '/' , 'test' ) ) . rejects . toThrow ( 'deriveKey is deprecated, please use getKey instead.' )
15+ } )
16+
1217 it ( 'should able to get key' , async ( ) => {
1318 const client = new DstackClient ( )
1419 const result = await client . getKey ( '/' , 'test' )
@@ -141,9 +146,9 @@ describe('DstackClient', () => {
141146 expect ( typeof isReachable ) . toBe ( 'boolean' )
142147 } )
143148
144- describe ( 'deprecated methods' , ( ) => {
149+ describe ( 'deprecated methods with TappdClient ' , ( ) => {
145150 it ( 'should support deprecated deriveKey method with warning' , async ( ) => {
146- const client = new DstackClient ( )
151+ const client = new TappdClient ( )
147152 const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
148153
149154 const result = await client . deriveKey ( '/' , 'test' )
@@ -155,7 +160,7 @@ describe('DstackClient', () => {
155160 } )
156161
157162 it ( 'should support deprecated tdxQuote method with warning' , async ( ) => {
158- const client = new DstackClient ( )
163+ const client = new TappdClient ( )
159164 const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
160165
161166 const result = await client . tdxQuote ( 'test data' )
@@ -167,7 +172,7 @@ describe('DstackClient', () => {
167172 } )
168173
169174 it ( 'should support tdxQuote with hash algorithm parameter' , async ( ) => {
170- const client = new DstackClient ( )
175+ const client = new TappdClient ( )
171176 const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
172177
173178 const result = await client . tdxQuote ( 'test data' , 'sha256' )
@@ -178,4 +183,54 @@ describe('DstackClient', () => {
178183 consoleSpy . mockRestore ( )
179184 } )
180185 } )
186+
187+ describe ( 'deprecated methods with DstackClient' , ( ) => {
188+ it ( 'should throws error in deriveKey method' , async ( ) => {
189+ const client = new DstackClient ( )
190+ const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
191+
192+ await expect ( ( ) => client . deriveKey ( '/' , 'test' ) ) . rejects . toThrow ( 'deriveKey is deprecated, please use getKey instead.' )
193+
194+ consoleSpy . mockRestore ( )
195+ } )
196+
197+ it ( 'should throws error in tdxQuote method without hash algorithm parameter' , async ( ) => {
198+ const client = new DstackClient ( )
199+ const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
200+
201+ await expect ( ( ) => client . tdxQuote ( 'test data' ) ) . rejects . toThrow ( 'tdxQuote only supports raw hash algorithm.' )
202+
203+ consoleSpy . mockRestore ( )
204+ } )
205+
206+ it ( "should throws error in tdxQuote method with hash algorithm parameter other than raw" , async ( ) => {
207+ const client = new DstackClient ( )
208+ const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
209+
210+ await expect ( ( ) => client . tdxQuote ( 'test data' , 'sha256' ) ) . rejects . toThrow ( 'tdxQuote only supports raw hash algorithm.' )
211+
212+ consoleSpy . mockRestore ( )
213+ } )
214+
215+ it ( 'should able to get quote with plain report_data in tdxQuote method with warning' , async ( ) => {
216+ const client = new DstackClient ( )
217+ const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
218+
219+ const result = await client . tdxQuote ( 'test data' , "raw" )
220+ expect ( result ) . toHaveProperty ( 'quote' )
221+ expect ( result ) . toHaveProperty ( 'event_log' )
222+ expect ( consoleSpy ) . toHaveBeenCalledWith ( 'tdxQuote is deprecated, please use getQuote instead' )
223+
224+ consoleSpy . mockRestore ( )
225+ } )
226+
227+ it ( 'should throws error in tdxQuote with hash algorithm parameter' , async ( ) => {
228+ const client = new DstackClient ( )
229+ const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
230+
231+ await expect ( ( ) => client . tdxQuote ( 'test data' , 'sha256' ) ) . rejects . toThrow ( 'tdxQuote only supports raw hash algorithm.' )
232+
233+ consoleSpy . mockRestore ( )
234+ } )
235+ } )
181236} )
0 commit comments