@facets-cloud/facetsctlv3
Version:
83 lines (82 loc) • 3.54 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const path = __importStar(require("path"));
const yaml = __importStar(require("js-yaml"));
const sinon = __importStar(require("sinon"));
const proxyquire_1 = __importDefault(require("proxyquire"));
describe('ArtifactService', () => {
const artifactInfo = {
projectName: 'test-project',
serviceName: 'test-service',
artifactoryName: 'test-artifactory',
repositoryUrl: ''
};
const artifactFilePath = path.join(process.cwd(), 'artifact-info.facets.yaml');
let fsStub;
let ArtifactService;
beforeEach(() => {
fsStub = {
existsSync: sinon.stub(),
readFileSync: sinon.stub(),
writeFileSync: sinon.stub(),
};
ArtifactService = (0, proxyquire_1.default)('../../src/services/artifactService', {
fs: fsStub,
}).ArtifactService;
});
afterEach(() => {
sinon.restore();
});
describe('getArtifactFilePath', () => {
it('should return the correct file path', () => {
const filePath = ArtifactService.getArtifactFilePath();
(0, chai_1.expect)(filePath).to.equal(artifactFilePath);
});
});
describe('readArtifactInfo', () => {
it('should throw an error if the artifact file does not exist', () => {
fsStub.existsSync.returns(false);
(0, chai_1.expect)(() => ArtifactService.readArtifactInfo()).to.throw(`Artifact file not found. Please run 'facetsctl artifact init' to create the artifact file.`);
});
it('should read and return artifact information if the file exists', () => {
const fileContent = yaml.dump(artifactInfo);
fsStub.existsSync.returns(true);
fsStub.readFileSync.returns(fileContent);
const result = ArtifactService.readArtifactInfo();
(0, chai_1.expect)(result).to.deep.equal(artifactInfo);
});
});
describe('writeArtifactInfo', () => {
it('should write the artifact information to the file', () => {
ArtifactService.writeArtifactInfo(artifactInfo);
(0, chai_1.expect)(fsStub.writeFileSync.calledOnceWithExactly(artifactFilePath, yaml.dump(artifactInfo), 'utf8')).to.be.true;
});
});
});