Skip to content
Snippets Groups Projects
Unverified Commit 4a300e71 authored by Cam Saül's avatar Cam Saül
Browse files

Add some frontend unit tests for STRING_LIKE :100:

parent 52d699d3
No related branches found
No related tags found
No related merge requests found
......@@ -93,7 +93,7 @@ export function isFieldType(type, field) {
export function getFieldType(field) {
// try more specific types first, then more generic types
for (const type of [DATE_TIME, LOCATION, COORDINATE, NUMBER, STRING, BOOLEAN]) {
for (const type of [DATE_TIME, LOCATION, COORDINATE, NUMBER, STRING, STRING_LIKE, BOOLEAN]) {
if (isFieldType(type, field)) return type;
}
}
......
......@@ -2,6 +2,7 @@ import {
getFieldType,
DATE_TIME,
STRING,
STRING_LIKE,
NUMBER,
BOOLEAN,
LOCATION,
......@@ -40,6 +41,10 @@ describe('schema_metadata', () => {
expect(getFieldType({ special_type: TYPE.Latitude })).toEqual(COORDINATE)
expect(getFieldType({ special_type: TYPE.Longitude })).toEqual(COORDINATE)
});
it('should know something that is string-like', () => {
expect(getFieldType({ base_type: TYPE.StringLike })).toEqual(STRING_LIKE);
expect(getFieldType({ base_type: TYPE.IPAddress })).toEqual(STRING_LIKE);
});
it('should know what it doesn\'t know', () => {
expect(getFieldType({ base_type: 'DERP DERP DERP' })).toEqual(undefined)
});
......
......@@ -47,22 +47,24 @@
(doseq [{:keys [keypath value]} (driver/table-rows-seq driver database metabase-metadata-table)]
;; TODO: this does not support schemas in dbs :(
(let [[_ table-name field-name k] (re-matches #"^([^.]+)\.(?:([^.]+)\.)?([^.]+)$" keypath)]
(try (when-not (if field-name
(when-let [table-id (db/select-one-id Table
;; TODO: this needs to support schemas
;; TODO: eventually limit this to "core" schema tables
:db_id (:id database)
:name table-name
:active true)]
(db/update-where! Field {:name field-name
:table_id table-id}
;; ignore legacy entries that try to set field_type since it's no longer part of Field
(when-not (= (keyword k) :field_type)
(try (when-not (if field-name
(when-let [table-id (db/select-one-id Table
;; TODO: this needs to support schemas
;; TODO: eventually limit this to "core" schema tables
:db_id (:id database)
:name table-name
:active true)]
(db/update-where! Field {:name field-name
:table_id table-id}
(keyword k) value))
(db/update-where! Table {:name table-name
:db_id (:id database)}
(keyword k) value))
(db/update-where! Table {:name table-name
:db_id (:id database)}
(keyword k) value))
(log/error (u/format-color "Error syncing _metabase_metadata: no matching keypath: %s" keypath)))
(catch Throwable e
(log/error (u/format-color 'red "Error in _metabase_metadata: %s" (.getMessage e))))))))
(log/error (u/format-color "Error syncing _metabase_metadata: no matching keypath: %s" keypath)))
(catch Throwable e
(log/error (u/format-color 'red "Error in _metabase_metadata: %s" (.getMessage e)))))))))
(defn- save-table-fields!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment