Skip to content

Commit

Permalink
fix(e2e): Making tests deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Aug 10, 2020
1 parent a4d9447 commit 175cc2e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/helpers/db-test.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const dbType = process.env.NESTJS_QUERY_DB_TYPE ?? 'postgres';
export const truncateSql = (table: string): string[] => {
if (dbType === 'mysql') {
return [`DELETE FROM ${table}`, `ALTER TABLE ${table} AUTO_INCREMENT = 1`];
return [`DELETE FROM \`${table}\``, `ALTER TABLE \`${table}\` AUTO_INCREMENT = 1`];
}
return [`TRUNCATE ${table} RESTART IDENTITY CASCADE`];
return [`TRUNCATE "${table}" RESTART IDENTITY CASCADE`];
};

interface QueryExecutor {
Expand Down
2 changes: 2 additions & 0 deletions examples/helpers/sequelize.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const sequelizeMysqlOptions = (
database,
autoLoadModels: true,
synchronize: true,
logging: false,
...overrides,
};
};
Expand All @@ -31,6 +32,7 @@ export const sequelizePostgresOptions = (
database,
autoLoadModels: true,
synchronize: true,
logging: false,
...overrides,
};
};
Expand Down
2 changes: 1 addition & 1 deletion examples/no-paging/e2e/todo-item.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('TodoItemResolver (noPaging - e2e)', () => {
variables: {},
query: `{
todoItem(id: 1) {
subTasks {
subTasks(sorting: { field: id, direction: ASC }) {
${subTaskFields}
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/offset-paging/e2e/tag.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ describe('TagResolver (limitOffset - e2e)', () => {
const { id, todoItems }: { id: string; todoItems: TodoItemDTO[] } = body.data.addTodoItemsToTag;
expect(id).toBe('1');
expect(todoItems).toHaveLength(5);
expect(todoItems.map((e) => e.title)).toEqual([
'Create Nest App',
expect(todoItems.map((e) => e.title).sort()).toEqual([
'Add Todo Item Resolver',
'Create Entity',
'Create Entity Service',
'Add Todo Item Resolver',
'Create Nest App',
'How to create item With Sub Tasks',
]);
});
Expand Down Expand Up @@ -619,7 +619,7 @@ describe('TagResolver (limitOffset - e2e)', () => {
const { id, todoItems }: { id: string; todoItems: TodoItemDTO[] } = body.data.removeTodoItemsFromTag;
expect(id).toBe('1');
expect(todoItems).toHaveLength(2);
expect(todoItems.map((e) => e.title)).toEqual(['Create Nest App', 'Create Entity']);
expect(todoItems.map((e) => e.title).sort()).toEqual(['Create Entity', 'Create Nest App']);
});
});
});
Expand Down

0 comments on commit 175cc2e

Please sign in to comment.