-
Notifications
You must be signed in to change notification settings - Fork 1
/
SchemaTest.min.js
1 lines (1 loc) · 1.63 KB
/
SchemaTest.min.js
1
var Database=JQB.Schema.Database,Table=JQB.Schema.Table;describe("ParseSchema",function(){it("should parse simple tables and columns",function(){var n=new Database("accounts,id,char,PRI\naccounts,fname,varchar,");expect(n.tables.length).toEqual(1),expect(n.tables[0].name).toEqual("accounts"),expect(n.tables[0].columns.length).toEqual(2),expect(n.tables[0].columns[0].name).toEqual("id"),expect(n.tables[0].columns[0].isPk).toEqual(!0),expect(n.tables[0].columns[0].datatype).toEqual("char"),expect(n.tables[0].columns[1].name).toEqual("fname"),expect(n.tables[0].columns[1].isPk).toEqual(!1),expect(n.tables[0].columns[1].datatype).toEqual("varchar")})}),describe("Singularize",function(){it("should drop the S on simple plurals",function(){expect(new Table("fields").singularize()).toEqual("field")}),it("should change IES plurals to Y",function(){expect(new Table("histories").singularize()).toEqual("history")}),it("should just return name otherwise",function(){expect(new Table("field").singularize()).toEqual("field")})}),describe("GuessForeignKeys",function(){var n=new Database("accounts,id,char,PRI\naccounts,name,varchar,\nusers,id,char,PRI\nusers,account_id,char,\nusers,name,varchar,\n"),t=function(n){expect(n.primary.name).toBe("accounts"),expect(n.primaryColumns[0].name).toBe("id"),expect(n.fkOwner.name).toBe("users"),expect(n.fkColumns[0].name).toBe("account_id")};it("should find a simple one",function(){var i=n.table("users").guessForeignKeys([n.table("accounts")]);expect(i.length).toEqual(1),t(i[0])}),it("should work backwards, too",function(){var i=n.table("accounts").guessForeignKeys([n.table("users")]);expect(i.length).toEqual(1),t(i[0])})})