How to use validateIdField method in wpt

Best JavaScript code snippet using wpt

RTCStats-helper.js

Source:RTCStats-helper.js Github

copy

Full Screen

...98// that the linked stats object is found in the stats report99// and have the type field value same as expected type100// It doesn't validate the other fields of the linked stats101// as validateStatsReport already does all validations102function validateIdField(statsReport, stats, field, type) {103 assert_string_field(stats, field);104 const linkedStats = getStatsById(statsReport, stats[field]);105 assert_equals(linkedStats.type, type,106 `Expect linked stats object to have type ${type}`);107}108function validateOptionalIdField(statsReport, stats, field, type) {109 if(stats[field] !== undefined) {110 validateIdField(statsReport, stats, field, type);111 }112}113/*114 [webrtc-pc]115 8.4. RTCStats Dictionary116 dictionary RTCStats {117 required DOMHighResTimeStamp timestamp;118 required RTCStatsType type;119 required DOMString id;120 };121 */122function validateRtcStats(statsReport, stats) {123 assert_number_field(stats, 'timestamp');124 assert_string_field(stats, 'type');125 assert_string_field(stats, 'id');126}127/*128 [webrtc-stats]129 7.1. RTCRTPStreamStats dictionary130 dictionary RTCRTPStreamStats : RTCStats {131 unsigned long ssrc;132 DOMString mediaType;133 DOMString trackId;134 DOMString transportId;135 DOMString codecId;136 unsigned long firCount;137 unsigned long pliCount;138 unsigned long nackCount;139 unsigned long sliCount;140 unsigned long long qpSum;141 };142 mediaType of type DOMString143 Either "audio" or "video".144 [webrtc-pc]145 8.6. Mandatory To Implement Stats146 - RTCRTPStreamStats, with attributes ssrc, mediaType, trackId,147 transportId, codecId, nackCount148 */149function validateRtpStreamStats(statsReport, stats) {150 validateRtcStats(statsReport, stats);151 assert_unsigned_int_field(stats, 'ssrc');152 assert_string_field(stats, 'mediaType');153 assert_enum_field(stats, 'mediaType', ['audio', 'video'])154 validateIdField(statsReport, stats, 'trackId', 'track');155 validateIdField(statsReport, stats, 'transportId', 'transport');156 validateIdField(statsReport, stats, 'codecId', 'codec');157 assert_optional_unsigned_int_field(stats, 'firCount');158 assert_optional_unsigned_int_field(stats, 'pliCount');159 assert_optional_unsigned_int_field(stats, 'nackCount');160 assert_optional_unsigned_int_field(stats, 'sliCount');161 assert_optional_unsigned_int_field(stats, 'qpSum');162}163/*164 [webrtc-stats]165 7.2. RTCCodecStats dictionary166 dictionary RTCCodecStats : RTCStats {167 unsigned long payloadType;168 RTCCodecType codecType;169 DOMString transportId;170 DOMString mimeType;171 unsigned long clockRate;172 unsigned long channels;173 DOMString sdpFmtpLine;174 DOMString implementation;175 };176 enum RTCCodecType {177 "encode",178 "decode",179 };180 [webrtc-pc]181 8.6. Mandatory To Implement Stats182 - RTCCodecStats, with attributes payloadType, codec, clockRate, channels, sdpFmtpLine183 */184function validateCodecStats(statsReport, stats) {185 validateRtcStats(statsReport, stats);186 assert_unsigned_int_field(stats, 'payloadType');187 assert_optional_enum_field(stats, 'codecType', ['encode', 'decode']);188 validateOptionalIdField(statsReport, stats, 'transportId', 'transport');189 assert_optional_string_field(stats, 'mimeType');190 assert_unsigned_int_field(stats, 'clockRate');191 assert_optional_unsigned_int_field(stats, 'channels');192 assert_optional_string_field(stats, 'sdpFmtpLine');193 assert_optional_string_field(stats, 'implementation');194}195/*196 [webrtc-stats]197 7.3. RTCReceivedRTPStreamStats dictionary198 dictionary RTCReceivedRTPStreamStats : RTCRTPStreamStats {199 unsigned long packetsReceived;200 unsigned long long bytesReceived;201 long packetsLost;202 double jitter;203 double fractionLost;204 unsigned long packetsDiscarded;205 unsigned long packetsFailedDecryption;206 unsigned long packetsRepaired;207 unsigned long burstPacketsLost;208 unsigned long burstPacketsDiscarded;209 unsigned long burstLossCount;210 unsigned long burstDiscardCount;211 double burstLossRate;212 double burstDiscardRate;213 double gapLossRate;214 double gapDiscardRate;215 };216 [webrtc-pc]217 8.6. Mandatory To Implement Stats218 - RTCReceivedRTPStreamStats, with all required attributes from its219 inherited dictionaries, and also attributes packetsReceived,220 bytesReceived, packetsLost, jitter, packetsDiscarded221 */222function validateReceivedRtpStreamStats(statsReport, stats) {223 validateRtpStreamStats(statsReport, stats);224 assert_unsigned_int_field(stats, 'packetsReceived');225 assert_unsigned_int_field(stats, 'bytesReceived');226 assert_unsigned_int_field(stats, 'packetsLost');227 assert_number_field(stats, 'jitter');228 assert_optional_number_field(stats, 'fractionLost');229 assert_unsigned_int_field(stats, 'packetsDiscarded');230 assert_optional_unsigned_int_field(stats, 'packetsFailedDecryption');231 assert_optional_unsigned_int_field(stats, 'packetsRepaired');232 assert_optional_unsigned_int_field(stats, 'burstPacketsLost');233 assert_optional_unsigned_int_field(stats, 'burstPacketsDiscarded');234 assert_optional_unsigned_int_field(stats, 'burstLossCount');235 assert_optional_unsigned_int_field(stats, 'burstDiscardCount');236 assert_optional_number_field(stats, 'burstLossRate');237 assert_optional_number_field(stats, 'burstDiscardRate');238 assert_optional_number_field(stats, 'gapLossRate');239 assert_optional_number_field(stats, 'gapDiscardRate');240}241/*242 [webrtc-stats]243 7.4. RTCInboundRTPStreamStats dictionary244 dictionary RTCInboundRTPStreamStats : RTCReceivedRTPStreamStats {245 DOMString remoteId;246 unsigned long framesDecoded;247 DOMHighResTimeStamp lastPacketReceivedTimestamp;248 };249 [webrtc-pc]250 8.6. Mandatory To Implement Stats251 - RTCInboundRTPStreamStats, with all required attributes from its inherited252 dictionaries, and also attributes remoteId, framesDecoded253 */254function validateInboundRtpStreamStats(statsReport, stats) {255 validateReceivedRtpStreamStats(statsReport, stats);256 validateIdField(statsReport, stats, 'remoteId', 'remote-outbound-rtp');257 assert_unsigned_int_field(stats, 'framesDecoded');258 assert_optional_number_field(stats, 'lastPacketReceivedTimeStamp');259}260/*261 [webrtc-stats]262 7.5. RTCRemoteInboundRTPStreamStats dictionary263 dictionary RTCRemoteInboundRTPStreamStats : RTCReceivedRTPStreamStats {264 DOMString localId;265 double roundTripTime;266 };267 [webrtc-pc]268 8.6. Mandatory To Implement Stats269 - RTCRemoteInboundRTPStreamStats, with all required attributes from its270 inherited dictionaries, and also attributes localId, roundTripTime271 */272function validateRemoteInboundRtpStreamStats(statsReport, stats) {273 validateReceivedRtpStreamStats(statsReport, stats);274 validateIdField(statsReport, stats, 'localId', 'outbound-rtp');275 assert_number_field(stats, 'roundTripTime');276}277/*278 [webrtc-stats]279 7.6. RTCSentRTPStreamStats dictionary280 dictionary RTCSentRTPStreamStats : RTCRTPStreamStats {281 unsigned long packetsSent;282 unsigned long packetsDiscardedOnSend;283 unsigned long long bytesSent;284 unsigned long long bytesDiscardedOnSend;285 };286 [webrtc-pc]287 8.6. Mandatory To Implement Stats288 - RTCSentRTPStreamStats, with all required attributes from its inherited289 dictionaries, and also attributes packetsSent, bytesSent290 */291function validateSentRtpStreamStats(statsReport, stats) {292 validateRtpStreamStats(statsReport, stats);293 assert_unsigned_int_field(stats, 'packetsSent');294 assert_optional_unsigned_int_field(stats, 'packetsDiscardedOnSend');295 assert_unsigned_int_field(stats, 'bytesSent');296 assert_optional_unsigned_int_field(stats, 'bytesDiscardedOnSend');297}298/*299 [webrtc-stats]300 7.7. RTCOutboundRTPStreamStats dictionary301 dictionary RTCOutboundRTPStreamStats : RTCSentRTPStreamStats {302 DOMString remoteId;303 DOMHighResTimeStamp lastPacketSentTimestamp;304 double targetBitrate;305 unsigned long framesEncoded;306 double totalEncodeTime;307 double averageRTCPInterval;308 };309 [webrtc-pc]310 8.6. Mandatory To Implement Stats311 - RTCOutboundRTPStreamStats, with all required attributes from its312 inherited dictionaries, and also attributes remoteId, framesEncoded313 */314function validateOutboundRtpStreamStats(statsReport, stats) {315 validateSentRtpStreamStats(statsReport, stats)316 validateIdField(statsReport, stats, 'remoteId', 'remote-inbound-rtp');317 assert_optional_number_field(stats, 'lastPacketSentTimestamp');318 assert_optional_number_field(stats, 'targetBitrate');319 if (stats['mediaType'] == 'video') {320 assert_unsigned_int_field(stats, 'framesEncoded');321 }322 assert_optional_number_field(stats, 'totalEncodeTime');323 assert_optional_number_field(stats, 'averageRTCPInterval');324}325/*326 [webrtc-stats]327 7.8. RTCRemoteOutboundRTPStreamStats dictionary328 dictionary RTCRemoteOutboundRTPStreamStats : RTCSentRTPStreamStats {329 DOMString localId;330 DOMHighResTimeStamp remoteTimestamp;331 };332 [webrtc-pc]333 8.6. Mandatory To Implement Stats334 - RTCRemoteOutboundRTPStreamStats, with all required attributes from its335 inherited dictionaries, and also attributes localId, remoteTimestamp336 */337function validateRemoteOutboundRtpStreamStats(statsReport, stats) {338 validateSentRtpStreamStats(statsReport, stats);339 validateIdField(statsReport, stats, 'localId', 'inbound-rtp');340 assert_number_field(stats, 'remoteTimeStamp');341}342/*343 [webrtc-stats]344 7.9. RTCRTPContributingSourceStats345 dictionary RTCRTPContributingSourceStats : RTCStats {346 unsigned long contributorSsrc;347 DOMString inboundRtpStreamId;348 unsigned long packetsContributedTo;349 double audioLevel;350 };351 */352function validateContributingSourceStats(statsReport, stats) {353 validateRtcStats(statsReport, stats);354 assert_optional_unsigned_int_field(stats, 'contributorSsrc');355 validateOptionalIdField(statsReport, stats, 'inboundRtpStreamId', 'inbound-rtp');356 assert_optional_unsigned_int_field(stats, 'packetsContributedTo');357 assert_optional_number_field(stats, 'audioLevel');358}359/*360 [webrtc-stats]361 7.10. RTCPeerConnectionStats dictionary362 dictionary RTCPeerConnectionStats : RTCStats {363 unsigned long dataChannelsOpened;364 unsigned long dataChannelsClosed;365 unsigned long dataChannelsRequested;366 unsigned long dataChannelsAccepted;367 };368 [webrtc-pc]369 8.6. Mandatory To Implement Stats370 - RTCPeerConnectionStats, with attributes dataChannelsOpened, dataChannelsClosed371 */372function validatePeerConnectionStats(statsReport, stats) {373 validateRtcStats(statsReport, stats);374 assert_unsigned_int_field(stats, 'dataChannelsOpened');375 assert_unsigned_int_field(stats, 'dataChannelsClosed');376 assert_optional_unsigned_int_field(stats, 'dataChannelsRequested');377 assert_optional_unsigned_int_field(stats, 'dataChannelsAccepted');378}379/*380 [webrtc-stats]381 7.11. RTCMediaStreamStats dictionary382 dictionary RTCMediaStreamStats : RTCStats {383 DOMString streamIdentifier;384 sequence<DOMString> trackIds;385 };386 [webrtc-pc]387 8.6. Mandatory To Implement Stats388 - RTCMediaStreamStats, with attributes streamIdentifer, trackIds389 */390function validateMediaStreamStats(statsReport, stats) {391 validateRtcStats(statsReport, stats);392 assert_string_field(stats, 'streamIdentifier');393 assert_array_field(stats, 'trackIds');394 for(const trackId of stats.trackIds) {395 assert_equals(typeof trackId, 'string',396 'Expect trackId elements to be string');397 assert_true(statsReport.has(trackId),398 `Expect stats report to have stats object with id ${trackId}`);399 const trackStats = statsReport.get(trackId);400 assert_equals(trackStats.type, 'track',401 `Expect track stats object to have type 'track'`);402 }403}404/*405 [webrtc-stats]406 7.12. RTCMediaStreamTrackStats dictionary407 dictionary RTCMediaStreamTrackStats : RTCStats {408 DOMString trackIdentifier;409 boolean remoteSource;410 boolean ended;411 boolean detached;412 DOMString kind;413 DOMHighResTimeStamp estimatedPlayoutTimestamp;414 unsigned long frameWidth;415 unsigned long frameHeight;416 double framesPerSecond;417 unsigned long framesCaptured;418 unsigned long framesSent;419 unsigned long keyFramesSent;420 unsigned long framesReceived;421 unsigned long keyFramesReceived;422 unsigned long framesDecoded;423 unsigned long framesDropped;424 unsigned long framesCorrupted;425 unsigned long partialFramesLost;426 unsigned long fullFramesLost;427 double audioLevel;428 double totalAudioEnergy;429 boolean voiceActivityFlag;430 double echoReturnLoss;431 double echoReturnLossEnhancement;432 unsigned long long totalSamplesSent;433 unsigned long long totalSamplesReceived;434 double totalSamplesDuration;435 unsigned long long concealedSamples;436 unsigned long long concealmentEvents;437 double jitterBufferDelay;438 RTCPriorityType priority;439 };440 [webrtc-pc]441 4.9.1. RTCPriorityType Enum442 enum RTCPriorityType {443 "very-low",444 "low",445 "medium",446 "high"447 };448 8.6. Mandatory To Implement Stats449 - RTCMediaStreamTrackStats, with attributes trackIdentifier, remoteSource,450 ended, detached, frameWidth, frameHeight, framesPerSecond, framesSent,451 framesReceived, framesDecoded, framesDropped, framesCorrupted, audioLevel452 */453function validateMediaStreamTrackStats(statsReport, stats) {454 validateRtcStats(statsReport, stats);455 assert_string_field(stats, 'trackIdentifier');456 assert_boolean_field(stats, 'remoteSource');457 assert_boolean_field(stats, 'ended');458 assert_boolean_field(stats, 'detached');459 assert_optional_enum_field(stats, 'kind', ['audio', 'video']);460 assert_optional_number_field(stats, 'estimatedPlayoutTimestamp');461 if (stats['kind'] === 'video') {462 assert_unsigned_int_field(stats, 'frameWidth');463 assert_unsigned_int_field(stats, 'frameHeight');464 assert_number_field(stats, 'framesPerSecond');465 if (stats['framesSent']) {466 assert_optional_unsigned_int_field(stats, 'framesCaptured');467 assert_unsigned_int_field(stats, 'framesSent');468 assert_optional_unsigned_int_field(stats, 'keyFramesSent');469 } else {470 assert_unsigned_int_field(stats, 'framesReceived');471 assert_optional_unsigned_int_field(stats, 'keyFramesReceived');472 assert_unsigned_int_field(stats, 'framesDecoded');473 assert_unsigned_int_field(stats, 'framesDropped');474 assert_unsigned_int_field(stats, 'framesCorrupted');475 }476 assert_optional_unsigned_int_field(stats, 'partialFramesLost');477 assert_optional_unsigned_int_field(stats, 'fullFramesLost');478 } else {479 assert_number_field(stats, 'audioLevel');480 assert_optional_number_field(stats, 'totalAudioEnergy');481 assert_optional_boolean_field(stats, 'voiceActivityFlag');482 assert_optional_number_field(stats, 'echoReturnLoss');483 assert_optional_number_field(stats, 'echoReturnLossEnhancement');484 assert_optional_unsigned_int_field(stats, 'totalSamplesSent');485 assert_optional_unsigned_int_field(stats, 'totalSamplesReceived');486 assert_optional_number_field(stats, 'totalSamplesDuration');487 assert_optional_unsigned_int_field(stats, 'concealedSamples');488 assert_optional_unsigned_int_field(stats, 'concealmentEvents');489 assert_optional_number_field(stats, 'jitterBufferDelay');490 }491 assert_optional_enum_field(stats, 'priority',492 ['very-low', 'low', 'medium', 'high']);493}494/*495 [webrtc-stats]496 7.13. RTCDataChannelStats dictionary497 dictionary RTCDataChannelStats : RTCStats {498 DOMString label;499 DOMString protocol;500 long dataChannelIdentifier;501 DOMString transportId;502 RTCDataChannelState state;503 unsigned long messagesSent;504 unsigned long long bytesSent;505 unsigned long messagesReceived;506 unsigned long long bytesReceived;507 };508 [webrtc-pc]509 6.2. RTCDataChannel510 enum RTCDataChannelState {511 "connecting",512 "open",513 "closing",514 "closed"515 };516 8.6. Mandatory To Implement Stats517 - RTCDataChannelStats, with attributes label, protocol, datachannelId, state,518 messagesSent, bytesSent, messagesReceived, bytesReceived519 */520function validateDataChannelStats(statsReport, stats) {521 validateRtcStats(statsReport, stats);522 assert_string_field(stats, 'label');523 assert_string_field(stats, 'protocol');524 assert_int_field(stats, 'dataChannelIdentifier');525 validateOptionalIdField(statsReport, stats, 'transportId', 'transport');526 assert_enum_field(stats, 'state',527 ['connecting', 'open', 'closing', 'closed']);528 assert_unsigned_int_field(stats, 'messagesSent');529 assert_unsigned_int_field(stats, 'bytesSent');530 assert_unsigned_int_field(stats, 'messagesReceived');531 assert_unsigned_int_field(stats, 'bytesReceived');532}533/*534 [webrtc-stats]535 7.14. RTCTransportStats dictionary536 dictionary RTCTransportStats : RTCStats {537 unsigned long packetsSent;538 unsigned long packetsReceived;539 unsigned long long bytesSent;540 unsigned long long bytesReceived;541 DOMString rtcpTransportStatsId;542 RTCIceRole iceRole;543 RTCDtlsTransportState dtlsState;544 DOMString selectedCandidatePairId;545 DOMString localCertificateId;546 DOMString remoteCertificateId;547 };548 [webrtc-pc]549 5.5. RTCDtlsTransportState Enum550 enum RTCDtlsTransportState {551 "new",552 "connecting",553 "connected",554 "closed",555 "failed"556 };557 5.6. RTCIceRole Enum558 enum RTCIceRole {559 "controlling",560 "controlled"561 };562 8.6. Mandatory To Implement Stats563 - RTCTransportStats, with attributes bytesSent, bytesReceived,564 rtcpTransportStatsId, selectedCandidatePairId, localCertificateId,565 remoteCertificateId566 */567function validateTransportStats(statsReport, stats) {568 validateRtcStats(statsReport, stats);569 assert_optional_unsigned_int_field(stats, 'packetsSent');570 assert_optional_unsigned_int_field(stats, 'packetsReceived');571 assert_unsigned_int_field(stats, 'bytesSent');572 assert_unsigned_int_field(stats, 'bytesReceived');573 validateOptionalIdField(statsReport, stats, 'rtcpTransportStatsId',574 'transport');575 assert_optional_enum_field(stats, 'iceRole',576 ['controlling', 'controlled']);577 assert_optional_enum_field(stats, 'dtlsState',578 ['new', 'connecting', 'connected', 'closed', 'failed']);579 validateIdField(statsReport, stats, 'selectedCandidatePairId', 'candidate-pair');580 validateIdField(statsReport, stats, 'localCertificateId', 'certificate');581 validateIdField(statsReport, stats, 'remoteCertificateId', 'certificate');582}583/*584 [webrtc-stats]585 7.15. RTCIceCandidateStats dictionary586 dictionary RTCIceCandidateStats : RTCStats {587 DOMString transportId;588 boolean isRemote;589 RTCNetworkType networkType;590 DOMString ip;591 long port;592 DOMString protocol;593 RTCIceCandidateType candidateType;594 long priority;595 DOMString url;596 DOMString relayProtocol;597 boolean deleted = false;598 };599 enum RTCNetworkType {600 "bluetooth",601 "cellular",602 "ethernet",603 "wifi",604 "wimax",605 "vpn",606 "unknown"607 };608 [webrtc-pc]609 4.8.1.3. RTCIceCandidateType Enum610 enum RTCIceCandidateType {611 "host",612 "srflx",613 "prflx",614 "relay"615 };616 8.6. Mandatory To Implement Stats617 - RTCIceCandidateStats, with attributes ip, port, protocol, candidateType,618 priority, url619 */620function validateIceCandidateStats(statsReport, stats) {621 validateRtcStats(statsReport, stats);622 validateOptionalIdField(statsReport, stats, 'transportId', 'transport');623 assert_optional_boolean_field(stats, 'isRemote');624 assert_optional_enum_field(stats, 'networkType',625 ['bluetooth', 'cellular', 'ethernet', 'wifi', 'wimax', 'vpn', 'unknown'])626 assert_string_field(stats, 'ip');627 assert_int_field(stats, 'port');628 assert_string_field(stats, 'protocol');629 assert_enum_field(stats, 'candidateType',630 ['host', 'srflx', 'prflx', 'relay']);631 assert_int_field(stats, 'priority');632 assert_optional_string_field(stats, 'url');633 assert_optional_string_field(stats, 'relayProtocol');634 assert_optional_boolean_field(stats, 'deleted');635}636/*637 [webrtc-stats]638 7.16. RTCIceCandidatePairStats dictionary639 dictionary RTCIceCandidatePairStats : RTCStats {640 DOMString transportId;641 DOMString localCandidateId;642 DOMString remoteCandidateId;643 RTCStatsIceCandidatePairState state;644 unsigned long long priority;645 boolean nominated;646 unsigned long packetsSent;647 unsigned long packetsReceived;648 unsigned long long bytesSent;649 unsigned long long bytesReceived;650 DOMHighResTimeStamp lastPacketSentTimestamp;651 DOMHighResTimeStamp lastPacketReceivedTimestamp;652 DOMHighResTimeStamp firstRequestTimestamp;653 DOMHighResTimeStamp lastRequestTimestamp;654 DOMHighResTimeStamp lastResponseTimestamp;655 double totalRoundTripTime;656 double currentRoundTripTime;657 double availableOutgoingBitrate;658 double availableIncomingBitrate;659 unsigned long circuitBreakerTriggerCount;660 unsigned long long requestsReceived;661 unsigned long long requestsSent;662 unsigned long long responsesReceived;663 unsigned long long responsesSent;664 unsigned long long retransmissionsReceived;665 unsigned long long retransmissionsSent;666 unsigned long long consentRequestsSent;667 DOMHighResTimeStamp consentExpiredTimestamp;668 };669 enum RTCStatsIceCandidatePairState {670 "frozen",671 "waiting",672 "in-progress",673 "failed",674 "succeeded"675 };676 [webrtc-pc]677 8.6. Mandatory To Implement Stats678 - RTCIceCandidatePairStats, with attributes transportId, localCandidateId,679 remoteCandidateId, state, priority, nominated, bytesSent, bytesReceived, totalRoundTripTime, currentRoundTripTime680 */681function validateIceCandidatePairStats(statsReport, stats) {682 validateRtcStats(statsReport, stats);683 validateIdField(statsReport, stats, 'transportId', 'transport');684 validateIdField(statsReport, stats, 'localCandidateId', 'local-candidate');685 validateIdField(statsReport, stats, 'remoteCandidateId', 'remote-candidate');686 assert_enum_field(stats, 'state',687 ['frozen', 'waiting', 'in-progress', 'failed', 'succeeded']);688 assert_unsigned_int_field(stats, 'priority');689 assert_boolean_field(stats, 'nominated');690 assert_optional_unsigned_int_field(stats, 'packetsSent');691 assert_optional_unsigned_int_field(stats, 'packetsReceived');692 assert_unsigned_int_field(stats, 'bytesSent');693 assert_unsigned_int_field(stats, 'bytesReceived');694 assert_optional_number_field(stats, 'lastPacketSentTimestamp');695 assert_optional_number_field(stats, 'lastPacketReceivedTimestamp');696 assert_optional_number_field(stats, 'firstRequestTimestamp');697 assert_optional_number_field(stats, 'lastRequestTimestamp');698 assert_optional_number_field(stats, 'lastResponseTimestamp');699 assert_number_field(stats, 'totalRoundTripTime');...

Full Screen

Full Screen

notifications.js

Source:notifications.js Github

copy

Full Screen

...31 autoform: {32 omit: true33 },34 custom: function () {35 return validateIdField(this, 1);36 }37 },38 invitationId: {39 type: String,40 optional: true,41 autoform: {42 omit: true43 },44 custom: function () {45 return validateIdField(this, 2);46 }47 },48 commentId: {49 type: String,50 optional: true,51 autoform: {52 omit: true53 },54 custom: function () {55 return validateIdField(this, 3);56 }57 },58 productId: {59 type: String,60 optional: true,61 autoform: {62 omit: true63 }64 },65 createdAt: {66 type: Date,67 autoValue: function () {68 if (this.isInsert) return new Date;69 else if (this.isUpsert) return {$setOnInsert: new Date};70 else71 /* Prevent user from supplying their own date. */72 this.unset();73 },74 autoform: {75 omit: true76 }77 },78 updatedAt: {79 type: Date,80 autoValue: function () {81 if (this.isInsert || this.isUpdate) return new Date;82 else if (this.isUpsert) return {$setOnInsert: new Date};83 else84 /* Prevent user from supplying their own date. */85 this.unset();86 },87 autoform: {88 omit: true89 }90 }91}));92/**93 * Returns true if:94 * - type argument matches corresponding type field and ID field has been set.95 * - type argument does not match corresponding type field and ID has not been set.96 */97function validateIdField(context, type) {98 if (context.field('type').value == type) {99 if (!context.isSet || context.value === null || context.value === "") return "required";100 else return true;101 } else {102 if (context.isSet || context.value) return "notAllowed";103 else return true;104 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.validateIdField('Q12345');3var wptools = require('wptools');4wptools.validateIdField('Q12345', function(err, result) {5 if (err) {6 console.log(err);7 } else {8 console.log(result);9 }10});11var wptools = require('wptools');12wptools.validateIdField('Q12345', function(err, result) {13 if (err) {14 console.log(err);15 } else {16 console.log(result);17 }18}, true);19var wptools = require('wptools');20wptools.validateIdField('Q12345', function(err, result) {21 if (err) {22 console.log(err);23 } else {24 console.log(result);25 }26}, false);27var wptools = require('wptools');28wptools.validateIdField('Q12345', function(err, result) {29 if (err) {30 console.log(err);31 } else {32 console.log(result);33 }34}, false, 'en');35var wptools = require('wptools');36wptools.validateIdField('Q12345', function(err, result) {37 if (err) {38 console.log(err);39 } else {40 console.log(result);41 }42}, true, 'en');43var wptools = require('wptools');44wptools.validateIdField('Q12345', function(err, result) {45 if (err) {46 console.log(err);47 } else {48 console.log(result);49 }50}, true, 'en', 'wikidata');51var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var id = 'Q1';3var lang = 'en';4wptools.validateIdField(id, lang, function(err, result) {5 if (err) {6 console.log('Error: ' + err);7 } else {8 console.log(result);9 }10});11{ valid: true, id: 'Q1', lang: 'en' }12validateIdField() method13var wptools = require('wptools');14var id = 'Q1';15var lang = 'en';16wptools.validateIdField(id, lang, function(err, result) {17 if (err) {18 console.log('Error: ' + err);19 } else {20 console.log(result);21 }22});23{ valid: true, id: 'Q1', lang: 'en' }24validateLangField() method25var wptools = require('wptools');26var lang = 'en';27wptools.validateLangField(lang, function(err, result) {28 if (err) {29 console.log('Error: ' + err);30 } else {31 console.log(result);32 }33});34{ valid: true, lang: 'en' }35validatePageField() method36validatePageField() method

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('./wptools.js');2var id = 'Q42';3wptools.validateIdField(id, function (err, result) {4 if (err) {5 console.log(err);6 } else {7 console.log(result);8 }9});10var validateIdField = function (id, callback) {11 if (id[0] === 'Q') {12 callback(null, id);13 } else {14 callback('Invalid id field');15 }16};17module.exports = {18};19var async = require('async');20var wptools = require('./wptools.js');21var id = 'Q42';22async.waterfall([23 function (callback) {24 wptools.validateIdField(id, callback);25 },26 function (id, callback) {27 wptools.getIdData(id, callback);28 }29], function (err, result) {30 if (err) {31 console.log(err);32 } else {33 console.log(result);34 }35});36var validateIdField = function (id, callback) {37 if (id[0] === 'Q') {38 callback(null, id);39 } else {40 callback('Invalid id field');41 }42};43var getIdData = function (id, callback) {44 request(url, function (err, response, body) {45 if (err) {46 callback(err);47 } else {48 var data = JSON.parse(body);49 callback(null, data);50 }51 });52};53module.exports = {54};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var validateIdField = wptoolkit.validateIdField;3var id = "1234567890";4var isValid = validateIdField(id);5console.log(isValid);6var wptoolkit = {};7wptoolkit.validateIdField = function(id) {8 var isValid = false;9 if (id.length === 10) {10 isValid = true;11 }12 return isValid;13};14module.exports = wptoolkit;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var id = '123456789';3var idType = 'Aadhaar';4var result = wptoolkit.validateIdField(id, idType);5console.log(result);6var wptoolkit = require('wptoolkit');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = wptools('Albert Einstein');3wiki.validateIdField('Albert Einstein', function (err, id) {4 if(err) {5 console.log(err);6 } else {7 console.log(id);8 }9});10{ error: 'invalid id', id: 'Albert Einstein' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = wptools('Albert Einstein');3wp.get(function(err, resp) {4 console.log(resp);5});6var wptools = function (page) {7 this.page = page;8 this.get = function (callback) {9 callback(null, "test");10 }11};12module.exports = wptools;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = wptools.page('Barack Obama');3wiki.get(function(err, resp) {4 console.log(wiki.validateIdField());5});6var wptools = require('wptools');7var wiki = wptools.page('Barack Obama');8wiki.get(function(err, resp) {9 console.log(wiki.validateIdField());10});11var wptools = require('wptools');12var wiki = wptools.page('Barack Obama');13wiki.get(function(err, resp) {14 console.log(wiki.validateIdField());15});16var wptools = require('wptools');17var wiki = wptools.page('Barack Obama');18wiki.get(function(err, resp) {19 console.log(wiki.validateIdField());20});21var wptools = require('wptools');22var wiki = wptools.page('Barack Obama');23wiki.get(function(err, resp) {24 console.log(wiki.validateIdField());25});26var wptools = require('wptools');27var wiki = wptools.page('Barack Obama');28wiki.get(function(err, resp) {29 console.log(wiki.validateIdField());30});31var wptools = require('wptools');32var wiki = wptools.page('Barack Obama');33wiki.get(function(err, resp) {34 console.log(wiki.validateIdField());35});36var wptools = require('wptools');37var wiki = wptools.page('Barack Obama');38wiki.get(function(err, resp) {39 console.log(w

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var result = wptoolkit.validateIdField("1234567890");3console.log(result);4var wptoolkit = require('wptoolkit');5var result = wptoolkit.validateIdField("1234567890");6console.log(result);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful