Skip to content

Commit

Permalink
Merge pull request #29 from leabstrait/new-tests
Browse files Browse the repository at this point in the history
New test cases for migrations
  • Loading branch information
halvardssm authored May 23, 2020
2 parents e8ab6eb + 2d0ba21 commit e525c1f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
12 changes: 6 additions & 6 deletions cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export const filterAndSortFiles = (
files: Deno.DirEntry[],
queryResult: string | undefined,
): Deno.DirEntry[] => {
return files.filter((file: Deno.DirEntry): boolean => {
if (!regexFileName.test(file.name)) return false;
return files
.filter((file: Deno.DirEntry): boolean => {
if (!regexFileName.test(file.name)) return false;

if (queryResult === undefined) return true;
if (queryResult === undefined) return true;

return parseInt(file.name.split("-")[0]) >
new Date(queryResult).getTime();
})
return file.name > queryResult;
})
.sort((a, b) => parseInt(a?.name ?? "0") - parseInt(b?.name ?? "0"));
};

Expand Down
38 changes: 32 additions & 6 deletions tests/migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const strings = [
solution: [
"Database setup complete",
"Migrated 1587937822648-test.ts",
"Migrated 1587937822649-apple.ts",
"Migrated 1587937822650-mango.ts",
"Migration complete",
],
},
Expand All @@ -22,19 +24,43 @@ const strings = [
solution: ["Nothing to migrate"],
},
{
name: "Rollback",
name: "Rollback Mango",
string: TYPE_ROLLBACK,
solution: ["Rolled back 1587937822648-test.ts"],
solution: ["Rolled back 1587937822650-mango.ts"],
},
{
name: "Rollback empty",
name: "Rollback Apple",
string: TYPE_ROLLBACK,
solution: ["Nothing to rollback"],
solution: ["Rolled back 1587937822649-apple.ts"],
},
{
name: "Migrate",
name: "Migrate Apple and Mango",
string: TYPE_MIGRATE,
solution: ["Migrated 1587937822648-test.ts", "Migration complete"],
solution: [
"Migrated 1587937822649-apple.ts",
"Migrated 1587937822650-mango.ts",
"Migration complete",
],
},
{
name: "Rollback Mango",
string: TYPE_ROLLBACK,
solution: ["Rolled back 1587937822650-mango.ts"],
},
{
name: "Rollback Apple",
string: TYPE_ROLLBACK,
solution: ["Rolled back 1587937822649-apple.ts"],
},
{
name: "Rollback Test",
string: TYPE_ROLLBACK,
solution: ["Rolled back 1587937822648-test.ts"],
},
{
name: "Rollback empty",
string: TYPE_ROLLBACK,
solution: ["Nothing to rollback"],
},
];

Expand Down
13 changes: 13 additions & 0 deletions tests/migrations/1587937822649-apple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Schema } from "../../mod.ts";

export const up = (scema: Schema): void => {
scema.create("apple", (table) => {
table.id();
table.string("col_1", 10);
table.timestamps();
});
};

export const down = (schema: Schema): void => {
schema.drop("apple");
};
13 changes: 13 additions & 0 deletions tests/migrations/1587937822650-mango.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Schema } from "../../mod.ts";

export const up = (scema: Schema): void => {
scema.create("mango", (table) => {
table.id();
table.string("col_1", 10);
table.timestamps();
});
};

export const down = (schema: Schema): void => {
schema.drop("mango");
};

0 comments on commit e525c1f

Please sign in to comment.