|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +const {assert} = require('chai'); |
| 18 | +const {describe, it} = require('mocha'); |
| 19 | +const proxyquire = require('proxyquire').noCallThru(); |
| 20 | + |
| 21 | +const projectId = process.env.GOOGLE_CLOUD_PROJECT || 'test-project'; |
| 22 | + |
| 23 | +describe('tuning-job-get', () => { |
| 24 | + it('should get tuning job and return job name', async function () { |
| 25 | + this.timeout(1000000); |
| 26 | + |
| 27 | + const mockTuningJob = { |
| 28 | + name: 'test-tuning-job', |
| 29 | + experiment: 'test-experiment', |
| 30 | + tunedModel: { |
| 31 | + model: 'test-model', |
| 32 | + endpoint: 'test-endpoint', |
| 33 | + }, |
| 34 | + }; |
| 35 | + |
| 36 | + class MockTunings { |
| 37 | + async get({name}) { |
| 38 | + if (name !== 'TestJobName') |
| 39 | + throw new Error('Unexpected tuning job name'); |
| 40 | + return mockTuningJob; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + class MockGoogleGenAI { |
| 45 | + constructor() { |
| 46 | + this.tunings = new MockTunings(); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + const sample = proxyquire('../tuning/tuning-job-get.js', { |
| 51 | + '@google/genai': {GoogleGenAI: MockGoogleGenAI}, |
| 52 | + }); |
| 53 | + |
| 54 | + const response = await sample.getTuningJob('TestJobName', projectId); |
| 55 | + |
| 56 | + assert.strictEqual(response, 'test-tuning-job'); |
| 57 | + }); |
| 58 | +}); |
0 commit comments