11import { strictEqual } from 'assert' ;
2+ import { readFile } from 'fs/promises' ;
3+ import { join } from 'path' ;
24import { Plans } from '../plan' ;
35import Protocol , { ResourceType , waitFor } from '../protocol' ;
46
@@ -10,12 +12,15 @@ describe('Integration API', function () {
1012
1113 if ( token === undefined ) {
1214 // Skip test
15+ console . warn (
16+ '⚠️ Warning: Integration API Test being skipped due to API_TOKEN not defined'
17+ ) ;
1318 return ;
1419 }
1520
1621 const API = Protocol ( token , baseURL ) ;
1722
18- it ( 'Should add repository' , async function ( ) {
23+ it . skip ( 'Should deploy a repository' , async function ( ) {
1924 const { id } = await API . add (
2025 'https://github.com/metacall/examples.git' ,
2126 'master' ,
@@ -31,9 +36,6 @@ describe('Integration API', function () {
3136 'v1'
3237 ) ;
3338
34- console . log ( JSON . stringify ( resource , null , 2 ) ) ;
35- console . log ( resource . suffix ) ;
36-
3739 const deploy = await waitFor ( async cancel => {
3840 const deploy = await API . inspectByName ( resource . suffix ) ;
3941
@@ -46,9 +48,82 @@ describe('Integration API', function () {
4648 return deploy ;
4749 } ) ;
4850
49- console . log ( JSON . stringify ( deploy , null , 2 ) ) ;
50-
5151 strictEqual ( deploy . suffix , 'metacall-examples' ) ;
5252 strictEqual ( deploy . status , 'ready' ) ;
53+
54+ const result = await API . deployDelete (
55+ deploy . prefix ,
56+ deploy . suffix ,
57+ deploy . version
58+ ) ;
59+
60+ strictEqual ( result , 'Deploy Delete Succeed' ) ;
61+ } ) ;
62+
63+ it . skip ( 'Should deploy a package' , async function ( ) {
64+ const basePath = join (
65+ process . cwd ( ) ,
66+ 'src' ,
67+ 'test' ,
68+ 'resources' ,
69+ 'integration' ,
70+ 'api'
71+ ) ;
72+
73+ const fileBuffer = await readFile (
74+ join ( basePath , 'metacall-protocol-package-test.zip' )
75+ ) ;
76+
77+ const blob = new Blob ( [ fileBuffer ] , { type : 'application/zip' } ) ;
78+
79+ const { id } = await API . upload (
80+ 'metacall-protocol-package-test' ,
81+ blob ,
82+ [ ] ,
83+ [ 'nodejs' ]
84+ ) ;
85+
86+ strictEqual ( id , 'metacall-protocol-package-test' ) ;
87+
88+ const resource = await API . deploy (
89+ id ,
90+ [ ] ,
91+ Plans . Essential ,
92+ ResourceType . Package ,
93+ '19d499ed1ab' ,
94+ 'v1'
95+ ) ;
96+
97+ const deploy = await waitFor ( async cancel => {
98+ const deploy = await API . inspectByName ( resource . suffix ) ;
99+
100+ if ( deploy . status === 'create' ) {
101+ throw new Error ( 'Not ready yet' ) ;
102+ } else if ( deploy . status === 'fail' ) {
103+ cancel ( 'Deploy failed' ) ;
104+ }
105+
106+ return deploy ;
107+ } ) ;
108+
109+ strictEqual ( deploy . suffix , 'metacall-protocol-package-test' ) ;
110+ strictEqual ( deploy . status , 'ready' ) ;
111+
112+ const value = await API . call < string > (
113+ deploy . prefix ,
114+ deploy . suffix ,
115+ deploy . version ,
116+ 'test'
117+ ) ;
118+
119+ strictEqual ( value , 'OK' ) ;
120+
121+ const result = await API . deployDelete (
122+ deploy . prefix ,
123+ deploy . suffix ,
124+ deploy . version
125+ ) ;
126+
127+ strictEqual ( result , 'Deploy Delete Succeed' ) ;
53128 } ) ;
54129} ) ;
0 commit comments