Skip to content

Commit

Permalink
feat(user): add dismissedToasts (#67)
Browse files Browse the repository at this point in the history
* feat(user): add dismissedToasts

* Clarify types
  • Loading branch information
FosterSamuel authored Jun 28, 2022
1 parent 7a16d6a commit 57b1c7b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 58 deletions.
53 changes: 33 additions & 20 deletions test/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ajv = new AJV({ allErrors: true });
// Username
exports.test_username_null = () => {
const isValid = ajv.validate(User, {
username: null,
username: null
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -18,7 +18,7 @@ exports.test_username_null = () => {

exports.test_username_invalid_pattern = () => {
const isValid = ajv.validate(User, {
username: '!!!',
username: '!!!'
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -31,7 +31,7 @@ exports.test_username_invalid_pattern = () => {

exports.test_username_too_short = () => {
const isValid = ajv.validate(User, {
username: '',
username: ''
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 2);
Expand All @@ -49,7 +49,7 @@ exports.test_username_too_short = () => {

exports.test_username_too_long = () => {
const isValid = ajv.validate(User, {
username: 'a'.repeat(50),
username: 'a'.repeat(50)
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -68,7 +68,7 @@ exports.test_username_valid = () => {
// Name
exports.test_name_too_short = () => {
const isValid = ajv.validate(User, {
name: '',
name: ''
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -81,7 +81,7 @@ exports.test_name_too_short = () => {

exports.test_name_too_long = () => {
const isValid = ajv.validate(User, {
name: 'a'.repeat(50),
name: 'a'.repeat(50)
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -99,7 +99,7 @@ exports.test_name_valid = () => {
// BillingChecked
exports.test_billing_checked_null = () => {
const isValid = ajv.validate(User, {
billingChecked: null,
billingChecked: null
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -114,7 +114,7 @@ exports.test_billing_checked_valid = () => {
// Avatar
exports.test_avatar_too_short = () => {
const isValid = ajv.validate(User, {
avatar: 'abc',
avatar: 'abc'
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -127,7 +127,7 @@ exports.test_avatar_too_short = () => {

exports.test_avatar_too_long = () => {
const isValid = ajv.validate(User, {
avatar: 'a'.repeat(50),
avatar: 'a'.repeat(50)
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -140,7 +140,7 @@ exports.test_avatar_too_long = () => {

exports.test_avatar_invalid = () => {
const isValid = ajv.validate(User, {
avatar: 'n'.repeat(40),
avatar: 'n'.repeat(40)
});
assert.equal(isValid, false);
assert.equal(ajv.errors.length, 1);
Expand All @@ -158,7 +158,7 @@ exports.test_email_valid = () => {

exports.test_email_invalid = () => {
const isValid = ajv.validate(User, {
email: `${'n'.repeat(256)}@zeit.co`,
email: `${'n'.repeat(256)}@zeit.co`
});
assert.equal(isValid, false);
};
Expand All @@ -173,7 +173,7 @@ exports.test_platformVersion_null_valid = () => {

exports.test_platformVersion_zero_invalid = () => {
const isValid = ajv.validate(User, {
platformVersion: 0,
platformVersion: 0
});
assert.equal(isValid, false);
};
Expand All @@ -188,7 +188,7 @@ exports.test_platformVersion_two_valid = () => {

exports.test_platformVersion_three_invalid = () => {
const isValid = ajv.validate(User, {
platformVersion: 3,
platformVersion: 3
});
assert.equal(isValid, false);
};
Expand All @@ -211,14 +211,14 @@ exports.test_importFlowGitProvider_null_valid = () => {

exports.test_importFlowGitProvider_invalid_value = () => {
const isValid = ajv.validate(User, {
importFlowGitProvider: 'test',
importFlowGitProvider: 'test'
});
assert.equal(isValid, false);
};

exports.test_importFlowGitProvider_number_invalid = () => {
const isValid = ajv.validate(User, {
importFlowGitProvider: 10,
importFlowGitProvider: 10
});
assert.equal(isValid, false);
};
Expand All @@ -233,14 +233,14 @@ exports.test_importFlowGitNamespace_null_valid = () => {

exports.test_importFlowGitNamespace_number_invalid = () => {
const isValid = ajv.validate(User, {
importFlowGitNamespace: 10,
importFlowGitNamespace: 10
});
assert.strictEqual(isValid, false);
};

exports.test_importFlowGitNamespace_boolean_invalid = () => {
const isValid = ajv.validate(User, {
importFlowGitNamespace: true,
importFlowGitNamespace: true
});
assert.strictEqual(isValid, false);
};
Expand All @@ -259,7 +259,7 @@ exports.test_importFlowGitNamespaceId_null_valid = () => {

exports.test_importFlowGitNamespaceId_boolean_invalid = () => {
const isValid = ajv.validate(User, {
importFlowGitNamespaceId: true,
importFlowGitNamespaceId: true
});
assert.strictEqual(isValid, false);
};
Expand All @@ -270,7 +270,7 @@ exports.test_scopeId_valid = () => {

exports.test_scopeId_invalid = () => {
const isValid = ajv.validate(User, {
scopeId: null,
scopeId: null
});
assert.strictEqual(isValid, false);
};
Expand All @@ -289,7 +289,7 @@ exports.test_gitNamespaceId_null_valid = () => {

exports.test_gitNamespaceId_boolean_invalid = () => {
const isValid = ajv.validate(User, {
gitNamespaceId: true,
gitNamespaceId: true
});
assert.strictEqual(isValid, false);
};
Expand All @@ -302,3 +302,16 @@ exports.test_remoteCaching_valid = () => {
const isValid = ajv.validate(User, { remoteCaching: { enabled: 'yes' } });
assert.strictEqual(isValid, false);
};

exports.test_dismissedToasts_valid = () => {
assert(ajv.validate(User, { dismissedToasts: {} }));
};

exports.test_dismissedToasts_valid = () => {
assert(ajv.validate(User, { dismissedToasts: { exampleToast: { exampleScopeId: 1656442351576 } } }));
};

exports.test_dismissedToasts_valid = () => {
const isValid = ajv.validate(User, { dismissedToasts: []});
assert.strictEqual(isValid, false);
};
92 changes: 54 additions & 38 deletions user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,117 @@ const Username = {
type: 'string',
minLength: 1,
maxLength: 48,
pattern: '^[a-z0-9][a-z0-9-]*[a-z0-9]$',
pattern: '^[a-z0-9][a-z0-9-]*[a-z0-9]$'
};

const Name = {
type: 'string',
minLength: 1,
maxLength: 32,
maxLength: 32
};

const Email = {
type: 'string',
minLength: 5,
maxLength: 256,
maxLength: 256
};

const ImportFlowGitProvider = {
oneOf: [
{
enum: ['github', 'gitlab', 'bitbucket'],
'enum': ['github', 'gitlab', 'bitbucket']
},
{
type: 'null',
},
],
type: 'null'
}
]
};

const ImportFlowGitNamespace = {
oneOf: [
{
type: 'string',
type: 'string'
},
{
type: 'null',
},
],
type: 'null'
}
]
};

const ImportFlowGitNamespaceId = {
oneOf: [
{
type: 'string',
type: 'string'
},
{
type: 'number',
type: 'number'
},
{
type: 'null',
},
],
type: 'null'
}
]
};

const ScopeId = {
type: 'string',
type: 'string'
};

const GitNamespaceId = {
oneOf: [
{
type: 'string',
type: 'string'
},
{
type: 'number',
type: 'number'
},
{
type: 'null',
},
],
type: 'null'
}
]
};

const PlatformVersion = {
oneOf: [
{
// A `null` platform version means to always use the latest
type: 'null',
type: 'null'
},
{
type: 'integer',
minimum: 1,
maximum: 2,
},
],
maximum: 2
}
]
};

const Avatar = {
type: 'string',
minLength: 40,
maxLength: 40,
pattern: '^[0-9a-f]+$',
pattern: '^[0-9a-f]+$'
};

const Bio = {
type: 'string',
type: 'string'
};

const Website = {
type: 'string',
minLength: 4,
maxLength: 40,
maxLength: 40
};

const Profile = {
type: 'object',
properties: {
service: {
type: 'string',
type: 'string'
},
link: {
type: 'string',
},
type: 'string'
}
},
additionalProperties: false,
additionalProperties: false
};

const Profiles = {
Expand All @@ -121,17 +121,31 @@ const Profiles = {
maxItems: 100,
uniqueItems: true,
items: Profile,
additionalProperties: false,
additionalProperties: false
};

const RemoteCaching = {
type: 'object',
properties: {
enabled: {
type: 'boolean',
},
type: 'boolean'
}
},
additionalProperties: false,
additionalProperties: false
};


// Record<ToastName, Record<Scope, Date>>
const DismissedToasts = {
type: 'object',
patternProperties: {
'^.*$': {
'^.*$': {
type: 'number'
}
}
},
additionalProperties: false
};

const User = {
Expand All @@ -153,7 +167,8 @@ const User = {
scopeId: ScopeId,
gitNamespaceId: GitNamespaceId,
remoteCaching: RemoteCaching,
},
dismissedToasts: DismissedToasts
}
};

module.exports = {
Expand All @@ -168,4 +183,5 @@ module.exports = {
ImportFlowGitNamespaceId,
ScopeId,
GitNamespaceId,
DismissedToasts
};

0 comments on commit 57b1c7b

Please sign in to comment.