|
|
@@ -15,49 +15,123 @@
|
|
|
// limitations under the License.
|
|
|
(function() {
|
|
|
|
|
|
- describe("apiHelper.js", function() {
|
|
|
+ describe('apiHelper.js', function() {
|
|
|
var subject = ApiHelper.getInstance({
|
|
|
i18n: {},
|
|
|
user: 'testUser'
|
|
|
});
|
|
|
|
|
|
- it("should be singleton", function() {
|
|
|
+ it('should be singleton', function() {
|
|
|
var otherHelper = ApiHelper.getInstance();
|
|
|
- expect(subject == otherHelper).toBeTruthy();
|
|
|
+ expect(subject === otherHelper).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
- describe("success response that is actually an error", function () {
|
|
|
- it("should not determine that a success response is an error response if status is 0", function () {
|
|
|
+ describe('success response that is actually an error', function () {
|
|
|
+ it('should not determine that a success response is an error response if status is 0', function () {
|
|
|
expect(subject.successResponseIsError({ status: 0 })).toBeFalsy();
|
|
|
});
|
|
|
|
|
|
- it("should determine that a success response is an error response if status is 1", function () {
|
|
|
+ it('should determine that a success response is an error response if status is 1', function () {
|
|
|
expect(subject.successResponseIsError({ status: 1 })).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
- it("should determine that a success response is an error response if status is -1", function () {
|
|
|
+ it('should determine that a success response is an error response if status is -1', function () {
|
|
|
expect(subject.successResponseIsError({ status: -1 })).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
- it("should determine that a success response is an error response if status is -3", function () {
|
|
|
+ it('should determine that a success response is an error response if status is -3', function () {
|
|
|
expect(subject.successResponseIsError({ status: -3 })).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
- it("should determine that a success response is an error response if status is 500", function () {
|
|
|
+ it('should determine that a success response is an error response if status is 500', function () {
|
|
|
expect(subject.successResponseIsError({ status: 500 })).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
- it("should determine that a success response is an error response if code is 500", function () {
|
|
|
+ it('should determine that a success response is an error response if code is 500', function () {
|
|
|
expect(subject.successResponseIsError({ code: 500 })).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
- it("should determine that a success response is an error response if code is 503", function () {
|
|
|
+ it('should determine that a success response is an error response if code is 503', function () {
|
|
|
expect(subject.successResponseIsError({ code: 503 })).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
- it("should determine that a success response is an error response if it contains traceback", function () {
|
|
|
+ it('should determine that a success response is an error response if it contains traceback', function () {
|
|
|
expect(subject.successResponseIsError({ traceback: {} })).toBeTruthy();
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ describe('NavOpt', function () {
|
|
|
+ describe('Tables JSON generation', function () {
|
|
|
+ it('should add the default database when no database is found in the identifier chain', function () {
|
|
|
+ spyOn(subject, 'containsDatabase').and.callFake(function () {
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+ var result = subject.createNavOptDbTablesJson({
|
|
|
+ defaultDatabase: 'default',
|
|
|
+ sourceType: 'hive',
|
|
|
+ tables: [{ identifierChain: [{ name: 'some_table' }] }]
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(result).toEqual('["default.some_table"]');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should add the database from the identifier chain if found', function () {
|
|
|
+ spyOn(subject, 'containsDatabase').and.callFake(function () {
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ var result = subject.createNavOptDbTablesJson({
|
|
|
+ defaultDatabase: 'default',
|
|
|
+ sourceType: 'hive',
|
|
|
+ tables: [{ identifierChain: [{ name: 'some_db' }, { name: 'some_table' }] }]
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(result).toEqual('["some_db.some_table"]');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should support tables with same names as databases', function () {
|
|
|
+ spyOn(subject, 'containsDatabase').and.callFake(function () {
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ var result = subject.createNavOptDbTablesJson({
|
|
|
+ defaultDatabase: 'default',
|
|
|
+ sourceType: 'hive',
|
|
|
+ tables: [{ identifierChain: [{ name: 'table_and_db_name' }] }]
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(result).toEqual('["default.table_and_db_name"]');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should support tables with same names as databases', function () {
|
|
|
+ spyOn(subject, 'containsDatabase').and.callFake(function () {
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ var result = subject.createNavOptDbTablesJson({
|
|
|
+ defaultDatabase: 'default',
|
|
|
+ sourceType: 'hive',
|
|
|
+ tables: [{ identifierChain: [{ name: 'table_and_db_name' }, { name: 'table_and_db_name' }] }]
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(result).toEqual('["table_and_db_name.table_and_db_name"]');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should support multiple tables some with databases some without', function () {
|
|
|
+ spyOn(subject, 'containsDatabase').and.callFake(function () {
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ var result = subject.createNavOptDbTablesJson({
|
|
|
+ defaultDatabase: 'default',
|
|
|
+ sourceType: 'hive',
|
|
|
+ tables: [{ identifierChain: [{ name: 'a_table_from_default' }] }, { identifierChain: [{ name: 'other_db' }, { name: 'a_table_from_other_db' }] }]
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(result).toEqual('["default.a_table_from_default","other_db.a_table_from_other_db"]');
|
|
|
+ })
|
|
|
+ });
|
|
|
+ })
|
|
|
});
|
|
|
})();
|