Merge pull request #13097 from Budibase/enforce-example-com-emails-in-tests
Enforce using example.com as a domain for emails.
This commit is contained in:
commit
dc35e9d1c2
|
@ -44,7 +44,8 @@
|
||||||
"no-undef": "off",
|
"no-undef": "off",
|
||||||
"no-prototype-builtins": "off",
|
"no-prototype-builtins": "off",
|
||||||
"local-rules/no-budibase-imports": "error",
|
"local-rules/no-budibase-imports": "error",
|
||||||
"local-rules/no-test-com": "error"
|
"local-rules/no-test-com": "error",
|
||||||
|
"local-rules/email-domain-example-com": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,4 +51,41 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"email-domain-example-com": {
|
||||||
|
meta: {
|
||||||
|
type: "problem",
|
||||||
|
docs: {
|
||||||
|
description:
|
||||||
|
"enforce using the example.com domain for generator.email calls",
|
||||||
|
category: "Possible Errors",
|
||||||
|
recommended: false,
|
||||||
|
},
|
||||||
|
fixable: "code",
|
||||||
|
schema: [],
|
||||||
|
},
|
||||||
|
create: function (context) {
|
||||||
|
return {
|
||||||
|
CallExpression(node) {
|
||||||
|
if (
|
||||||
|
node.callee.type === "MemberExpression" &&
|
||||||
|
node.callee.object.name === "generator" &&
|
||||||
|
node.callee.property.name === "email" &&
|
||||||
|
node.arguments.length === 0
|
||||||
|
) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
message:
|
||||||
|
"Prefer using generator.email with the domain \"{ domain: 'example.com' }\".",
|
||||||
|
fix: function (fixer) {
|
||||||
|
return fixer.replaceText(
|
||||||
|
node,
|
||||||
|
'generator.email({ domain: "example.com" })'
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ export const account = (partial: Partial<Account> = {}): Account => {
|
||||||
return {
|
return {
|
||||||
accountId: uuid(),
|
accountId: uuid(),
|
||||||
tenantId: generator.word(),
|
tenantId: generator.word(),
|
||||||
email: generator.email(),
|
email: generator.email({ domain: "example.com" }),
|
||||||
tenantName: generator.word(),
|
tenantName: generator.word(),
|
||||||
hosting: Hosting.SELF,
|
hosting: Hosting.SELF,
|
||||||
createdAt: Date.now(),
|
createdAt: Date.now(),
|
||||||
|
|
|
@ -13,7 +13,7 @@ interface CreateUserRequestFields {
|
||||||
export function createUserRequest(userData?: Partial<CreateUserRequestFields>) {
|
export function createUserRequest(userData?: Partial<CreateUserRequestFields>) {
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
externalId: uuid(),
|
externalId: uuid(),
|
||||||
email: generator.email(),
|
email: `${uuid()}@example.com`,
|
||||||
firstName: generator.first(),
|
firstName: generator.first(),
|
||||||
lastName: generator.last(),
|
lastName: generator.last(),
|
||||||
username: generator.name(),
|
username: generator.name(),
|
||||||
|
|
|
@ -8,6 +8,7 @@ module FetchMock {
|
||||||
let mockSearch = false
|
let mockSearch = false
|
||||||
|
|
||||||
const func = async (url: any, opts: any) => {
|
const func = async (url: any, opts: any) => {
|
||||||
|
const { host, pathname } = new URL(url)
|
||||||
function json(body: any, status = 200) {
|
function json(body: any, status = 200) {
|
||||||
return {
|
return {
|
||||||
status,
|
status,
|
||||||
|
@ -34,7 +35,7 @@ module FetchMock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.includes("/api/global")) {
|
if (pathname.includes("/api/global")) {
|
||||||
const user = {
|
const user = {
|
||||||
email: "test@example.com",
|
email: "test@example.com",
|
||||||
_id: "us_test@example.com",
|
_id: "us_test@example.com",
|
||||||
|
@ -47,31 +48,31 @@ module FetchMock {
|
||||||
global: false,
|
global: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return url.endsWith("/users") && opts.method === "GET"
|
return pathname.endsWith("/users") && opts.method === "GET"
|
||||||
? json([user])
|
? json([user])
|
||||||
: json(user)
|
: json(user)
|
||||||
}
|
}
|
||||||
// mocked data based on url
|
// mocked data based on url
|
||||||
else if (url.includes("api/apps")) {
|
else if (pathname.includes("api/apps")) {
|
||||||
return json({
|
return json({
|
||||||
app1: {
|
app1: {
|
||||||
url: "/app1",
|
url: "/app1",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else if (url.includes("example.com")) {
|
} else if (host.includes("example.com")) {
|
||||||
return json({
|
return json({
|
||||||
body: opts.body,
|
body: opts.body,
|
||||||
url,
|
url,
|
||||||
method: opts.method,
|
method: opts.method,
|
||||||
})
|
})
|
||||||
} else if (url.includes("invalid.com")) {
|
} else if (host.includes("invalid.com")) {
|
||||||
return json(
|
return json(
|
||||||
{
|
{
|
||||||
invalid: true,
|
invalid: true,
|
||||||
},
|
},
|
||||||
404
|
404
|
||||||
)
|
)
|
||||||
} else if (mockSearch && url.includes("_search")) {
|
} else if (mockSearch && pathname.includes("_search")) {
|
||||||
const body = opts.body
|
const body = opts.body
|
||||||
const parts = body.split("tableId:")
|
const parts = body.split("tableId:")
|
||||||
let tableId
|
let tableId
|
||||||
|
@ -90,7 +91,7 @@ module FetchMock {
|
||||||
],
|
],
|
||||||
bookmark: "test",
|
bookmark: "test",
|
||||||
})
|
})
|
||||||
} else if (url.includes("google.com")) {
|
} else if (host.includes("google.com")) {
|
||||||
return json({
|
return json({
|
||||||
url,
|
url,
|
||||||
opts,
|
opts,
|
||||||
|
@ -177,7 +178,7 @@ module FetchMock {
|
||||||
} else if (url === "https://www.googleapis.com/oauth2/v4/token") {
|
} else if (url === "https://www.googleapis.com/oauth2/v4/token") {
|
||||||
// any valid response
|
// any valid response
|
||||||
return json({})
|
return json({})
|
||||||
} else if (url.includes("failonce.com")) {
|
} else if (host.includes("failonce.com")) {
|
||||||
failCount++
|
failCount++
|
||||||
if (failCount === 1) {
|
if (failCount === 1) {
|
||||||
return json({ message: "error" }, 500)
|
return json({ message: "error" }, 500)
|
||||||
|
|
|
@ -10,3 +10,4 @@ process.env.MOCK_REDIS = "1"
|
||||||
process.env.PLATFORM_URL = "http://localhost:10000"
|
process.env.PLATFORM_URL = "http://localhost:10000"
|
||||||
process.env.REDIS_PASSWORD = "budibase"
|
process.env.REDIS_PASSWORD = "budibase"
|
||||||
process.env.BUDIBASE_VERSION = "0.0.0+jest"
|
process.env.BUDIBASE_VERSION = "0.0.0+jest"
|
||||||
|
process.env.WORKER_URL = "http://localhost:10000"
|
||||||
|
|
|
@ -347,7 +347,7 @@ export default class TestConfiguration {
|
||||||
lastName = generator.last(),
|
lastName = generator.last(),
|
||||||
builder = { global: true },
|
builder = { global: true },
|
||||||
admin = { global: false },
|
admin = { global: false },
|
||||||
email = generator.email(),
|
email = generator.email({ domain: "example.com" }),
|
||||||
tenantId = this.getTenantId(),
|
tenantId = this.getTenantId(),
|
||||||
roles = {},
|
roles = {},
|
||||||
} = config
|
} = config
|
||||||
|
@ -512,7 +512,7 @@ export default class TestConfiguration {
|
||||||
|
|
||||||
async basicRoleHeaders() {
|
async basicRoleHeaders() {
|
||||||
return await this.roleHeaders({
|
return await this.roleHeaders({
|
||||||
email: generator.email(),
|
email: generator.email({ domain: "example.com" }),
|
||||||
builder: false,
|
builder: false,
|
||||||
prodApp: true,
|
prodApp: true,
|
||||||
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
|
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
|
||||||
|
@ -520,7 +520,7 @@ export default class TestConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
async roleHeaders({
|
async roleHeaders({
|
||||||
email = generator.email(),
|
email = generator.email({ domain: "example.com" }),
|
||||||
roleId = roles.BUILTIN_ROLE_IDS.ADMIN,
|
roleId = roles.BUILTIN_ROLE_IDS.ADMIN,
|
||||||
builder = false,
|
builder = false,
|
||||||
prodApp = true,
|
prodApp = true,
|
||||||
|
|
|
@ -147,7 +147,7 @@ describe("/api/global/groups", () => {
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Array.from({ length: 30 }).map(async (_, i) => {
|
Array.from({ length: 30 }).map(async (_, i) => {
|
||||||
const email = `user${i}@${generator.domain()}`
|
const email = `user${i}@example.com`
|
||||||
const user = await config.api.users.saveUser({
|
const user = await config.api.users.saveUser({
|
||||||
...structures.users.user(),
|
...structures.users.user(),
|
||||||
email,
|
email,
|
||||||
|
|
|
@ -84,7 +84,7 @@ describe("Accounts", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("searches by email", async () => {
|
it("searches by email", async () => {
|
||||||
const email = generator.email()
|
const email = generator.email({ domain: "example.com" })
|
||||||
|
|
||||||
// Empty result
|
// Empty result
|
||||||
const [_, emptyBody] = await config.api.accounts.search(email, "email")
|
const [_, emptyBody] = await config.api.accounts.search(email, "email")
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { generator } from "../../shared"
|
||||||
export const generateUser = (
|
export const generateUser = (
|
||||||
overrides: Partial<User> = {}
|
overrides: Partial<User> = {}
|
||||||
): CreateUserParams => ({
|
): CreateUserParams => ({
|
||||||
email: generator.email(),
|
email: generator.email({ domain: "example.com" }),
|
||||||
roles: {
|
roles: {
|
||||||
[generator.string({ length: 32, alpha: true, numeric: true })]:
|
[generator.string({ length: 32, alpha: true, numeric: true })]:
|
||||||
generator.word(),
|
generator.word(),
|
||||||
|
|
Loading…
Reference in New Issue