@@ -11,13 +11,18 @@ import babelTsParser from 'recast/parsers/babel-ts.js'
1111import { Identifier } from '@babel/types'
1212import { flytrapTransformArtifacts } from '../src/transform/index'
1313import {
14+ _fetchUploadedArtifacts ,
15+ _getArtifactsToUpload ,
1416 getArtifactsToUpload ,
1517 getCacheFilePath ,
1618 markArtifactAsUploaded ,
17- upsertArtifact
19+ upsertArtifact ,
20+ upsertArtifacts
1821} from '../src/transform/artifacts/cache'
1922import { Artifact } from '../src/exports'
2023import { rmSync } from 'fs'
24+ import { config } from 'dotenv'
25+ config ( )
2126
2227describe ( 'Artifacts for functions' , ( ) => {
2328 const arrowFunctionFixture = `
@@ -261,9 +266,17 @@ it('generates values same as transform', () => {
261266} )
262267
263268describe ( 'Cache' , ( ) => {
269+ const testEnvProjectId = process . env [ 'FLYTRAP_PROJECT_ID' ]
270+ const testEnvSecretApiKey = process . env [ 'FLYTRAP_SECRET_KEY' ]
271+ if ( ! testEnvProjectId ) {
272+ throw new Error ( `Flytrap Testing Environment project ID not defined.` )
273+ }
274+ if ( ! testEnvSecretApiKey ) {
275+ throw new Error ( `Flytrap Testing Environment secret API key not defined.` )
276+ }
264277 const cacheFilePath = getCacheFilePath ( 'mock-project-id' )
265278 const mockArtifact : Artifact = {
266- functionOrCallId : '' ,
279+ functionOrCallId : `mock-call-id- ${ new Date ( ) . toISOString ( ) } ` ,
267280 functionOrCallName : '' ,
268281 params : '' ,
269282 scopes : [ ] ,
@@ -278,6 +291,33 @@ describe('Cache', () => {
278291 rmSync ( cacheFilePath , { recursive : true } )
279292 } )
280293
294+ it ( '_fetchUploadedArtifacts' , async ( ) => {
295+ const uploadedArtifacts = await _fetchUploadedArtifacts ( testEnvProjectId , testEnvSecretApiKey )
296+ expect (
297+ uploadedArtifacts . find ( ( u ) => u . functionOrCallId === mockArtifact . functionOrCallId ) !==
298+ undefined
299+ )
300+ } )
301+
302+ it ( '_getArtifactsToUpload' , async ( ) => {
303+ const artifactsToUpload = await _getArtifactsToUpload ( testEnvProjectId , testEnvSecretApiKey , [
304+ mockArtifact
305+ ] )
306+ expect ( artifactsToUpload ) . toEqual ( [ mockArtifact ] )
307+ } )
308+
309+ it ( 'upsertArtifacts' , async ( ) => {
310+ const response = await upsertArtifacts ( testEnvProjectId , testEnvSecretApiKey , [ mockArtifact ] )
311+ expect ( response . includes ( mockArtifact . functionOrCallId ) )
312+ } )
313+
314+ it ( '_getArtifactsToUpload no longer include the mock artifact' , async ( ) => {
315+ const artifactsToUpload = await _getArtifactsToUpload ( testEnvProjectId , testEnvSecretApiKey , [
316+ mockArtifact
317+ ] )
318+ expect ( artifactsToUpload ) . toEqual ( [ ] )
319+ } )
320+
281321 it ( 'upserts artifact' , ( ) => {
282322 upsertArtifact ( 'mock-project-id' , mockArtifact )
283323 } )
0 commit comments