tmhcc-ir-apis
Version:
imageright APIs
46 lines (45 loc) • 2.4 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = __importDefault(require("../index"));
const authentication_1 = require("../imageright/api/authentication");
const imageright_1 = __importDefault(require("../imageright"));
jest.mock('../imageright/api/authentication');
jest.mock('../imageright');
describe('Library', () => {
const baseUrl = 'http://example.com';
const accessToken = 'test-token';
const username = 'test-user';
const password = 'test-pass';
let library;
beforeEach(() => {
library = new index_1.default(baseUrl);
});
it('should initialize with baseUrl and version', () => {
expect(library).toHaveProperty('baseUrl', baseUrl);
expect(library).toHaveProperty('version', '0.0.6');
});
it('should create API instance', () => __awaiter(void 0, void 0, void 0, function* () {
const api = yield library.createAPI({ AccessToken: accessToken });
expect(api).toBeInstanceOf(imageright_1.default);
expect(api).toHaveProperty('baseUrl', baseUrl);
expect(api).toHaveProperty('accessToken', accessToken);
}));
it('should authenticate and create API instance', () => __awaiter(void 0, void 0, void 0, function* () {
authentication_1.authenticate.mockResolvedValue({ AccessToken: accessToken });
const api = yield library.connect(username, password);
expect(authentication_1.authenticate).toHaveBeenCalledWith(baseUrl, username, password);
expect(api).toBeInstanceOf(imageright_1.default);
}));
});