Skip to content

Commit

Permalink
Corrected & renamed Rule E2.1 -> E6
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-looker committed Aug 9, 2023
1 parent 01856c3 commit 7cfa2ba
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 221 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ As of LAMS v3, you must opt-in via your `manifest.lkml` file to use the built-in
#rule: F4{} # Description or hidden
#rule: E1{} # Join with subst'n operator
#rule: E2{} # Join on PK for "one" joins
#rule: E6{} # FK joins are m:1
#rule: T1{} # Triggers use datagroups
#rule: T2{} # Primary keys in DT
#rule: W1{} # Block indentation

#rule: W1{} # Block indentation
```

### Rule Exemptions
Expand Down
186 changes: 0 additions & 186 deletions __tests__/e2-1.test.js

This file was deleted.

171 changes: 171 additions & 0 deletions __tests__/e6.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/* Copyright (c) 2018 Looker Data Sciences, Inc. See https://github.com/looker-open-source/look-at-me-sideways/blob/master/LICENSE.txt */
require('../lib/expect-to-contain-message');

const rule = require('../rules/e6.js');
const {parse} = require('lookml-parser');

describe('Rules', () => {
describe('E6', () => {
let info = {level: 'info'};
let error = {level: 'error'};
let e6 = {rule: 'E6'};

it('should not match and pass if there are no models', () => {
let result = rule(parse(`file: foo{}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 0 matches, 0 matches exempt, and 0 errors"

Check failure on line 16 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Strings must use singlequote

Check failure on line 16 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Missing trailing comma
});
expect(result).not.toContainMessage(error);
});

it('should not match and pass if there are no explores', () => {
let result = rule(parse(`model: foo {}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 0 matches, 0 matches exempt, and 0 errors"

Check failure on line 24 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Strings must use singlequote

Check failure on line 24 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Missing trailing comma
});
expect(result).not.toContainMessage(error);
});

it('should not match and pass if there are no joins', () => {
let result = rule(parse(`model: m {
explore: orders {}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 0 matches, 0 matches exempt, and 0 errors"

Check failure on line 34 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Strings must use singlequote

Check failure on line 34 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Missing trailing comma
});
expect(result).not.toContainMessage(error);
});

it('should not match and pass for joins without foreign_key', () => {
let result = rule(parse(`model: m {
explore: orders {
join: users {
relationship: many_to_one
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 0 matches, 0 matches exempt, and 0 errors"

Check failure on line 48 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Strings must use singlequote

Check failure on line 48 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Missing trailing comma
});
expect(result).not.toContainMessage(error);
});

it('should pass for implicit m:1 relationship', () => {
let result = rule(parse(`model: m {
explore: orders {
join: users {
foreign_key: user_id
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 1 matches, 0 matches exempt, and 0 errors"

Check failure on line 62 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Strings must use singlequote

Check failure on line 62 in __tests__/e6.test.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

Missing trailing comma
});
expect(result).not.toContainMessage(error);
});

it('should pass for explicit m:1 relationship', () => {
let result = rule(parse(`model: m {
explore: orders {
join: users {
relationship: many_to_one
foreign_key: user_id
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 1 matches, 0 matches exempt, and 0 errors"
});
expect(result).not.toContainMessage(error);
});

it('should pass when the FK is the base-view\'s PK and uses 1:1 relationship', () => {
let result = rule(parse(`model: m {
explore: orders {
join: order_derived_columns {
relationship: one_to_one
foreign_key: pk1_order_id
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 1 matches, 0 matches exempt, and 0 errors"
});
expect(result).not.toContainMessage(error);
});

it('should error if a *:m relationship is specified', () => {
let result = rule(parse(`model: m {
explore: orders {
join: users {
relationship: one_to_many
foreign_key: user_id
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 1 matches, 0 matches exempt, and 1 errors"
});
expect(result).toContainMessage({...e6, ...error});
});

it('should error if a 1:1 relationship is specified', () => {
let result = rule(parse(`model: m {
explore: orders {
join: users {
relationship: one_to_one
foreign_key: user_id
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 1 matches, 0 matches exempt, and 1 errors"
});
expect(result).toContainMessage({...e6, ...error});
});

it('should error if a *:m relationship is specified for joins from a pk', () => {
let result = rule(parse(`model: m {
explore: orders {
join: order_derived_columns {
relationship: one_to_many
foreign_key: pk1_order_id
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 1 matches, 0 matches exempt, and 1 errors"
});
expect(result).toContainMessage({...e6, ...error});
});

it('should error if a m:1 relationship is specified for joins from a pk', () => {
let result = rule(parse(`model: m {
explore: orders {
join: order_derived_columns {
relationship: many_to_one
foreign_key: pk1_order_id
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 1 matches, 0 matches exempt, and 1 errors"
});
expect(result).toContainMessage({...e6, ...error});
});

it('should error if a m:1 relationship is implicit for joins from a pk', () => {
let result = rule(parse(`model: m {
explore: orders {
join: order_derived_columns {
foreign_key: pk1_order_id
}
}
}`));
expect(result).toContainMessage({...e6, ...info,
description: "Rule E6 summary: 1 matches, 0 matches exempt, and 1 errors"
});
expect(result).toContainMessage({...e6, ...error});
});
});
});
Loading

0 comments on commit 7cfa2ba

Please sign in to comment.